You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
859 B
C++
38 lines
859 B
C++
#include <cstdio>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
const int N = 1e5 + 5;
|
|
int dist[N], l, n, m;
|
|
bool check(int x)
|
|
{
|
|
if (dist[0] > x)
|
|
return false;
|
|
int d = 0, cnt = 1;
|
|
for (int i = 1; i < n; i++)
|
|
if (dist[i] - d > x)
|
|
{
|
|
d = dist[i - 1];
|
|
if (dist[i] - d > x)
|
|
return false;
|
|
cnt++;
|
|
}
|
|
return cnt <= m;
|
|
}
|
|
int main()
|
|
{
|
|
while (~scanf("%d%d%d", &l, &n, &m))
|
|
{
|
|
for (int i = 0; i < n; i++)
|
|
scanf("%d", &dist[i]);
|
|
dist[n++] = l;
|
|
sort(dist, dist + n);
|
|
int b = 0, e = l, ans = l, mid;
|
|
while (b < e)
|
|
if (check(mid = (b + e) / 2))
|
|
ans = e = mid;
|
|
else
|
|
b = mid + 1;
|
|
printf("%d\n", ans);
|
|
}
|
|
return 0;
|
|
} |