-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2678.cpp
40 lines (40 loc) · 822 Bytes
/
P2678.cpp
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
#include <bits/stdc++.h>
using namespace std;
long L, N, M;
long s[50002];
int main()
{
cin >> L >> N >> M;
long maxl = 0;
for (int i = 1; i <= N; i++)
{
cin >> s[i];
maxl = max(s[i] - s[i - 1], maxl);
}
s[N + 1] = L;
maxl=max(s[N+1]-s[N],maxl);
long l = 1, r = maxl;
while (l < r)
{
list<long> ls;
long mid = (l + r + 1) >> 1;
int sum = 0;
for (int i = 0; i <= N + 1; i++)
{
ls.push_back(s[i]);
list<long>::iterator it = ls.end();
if (ls.size()>1&& *(--it) - *(--it) < mid)
{
ls.pop_back();
sum++;
}
}
if (sum <= M)
{
l = mid;
}
else
r = mid - 1;
}
cout << l;
}