-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18877.cpp
More file actions
49 lines (44 loc) · 879 Bytes
/
18877.cpp
File metadata and controls
49 lines (44 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n, m;
pair<ll, ll> arr[101010];
bool ok(ll x)
{
ll cur = 0, cnt = 0;
for(int i =0 ;i < m;i++){
cur = max(cur , arr[i].first);
while(cur <= arr[i].second){
cnt++;
if(cnt >= n) return 1;
cur += x;
}
}
return 0;
}
int main()
{
fastio;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> arr[i].first >> arr[i].second;
}
sort(arr, arr + m);
ll ans = 0;
ll s = 1, e = 1e18;
while (s <= e)
{
ll m = s + e >> 1;
if(ok(m)) {
s = m + 1;
ans = m;
}
else e = m - 1;
}
cout << ans << "\n";
return 0;
}