二分查找 习题
AcWing 519.跳石头
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 100010;
int d, n, m;
int a[N];
bool judge(int x)
{
int tol = 0;
int i = 0;
int now = 0;
while (i < n + 1)
{
i++;
if (a[i] - a[now] < x) tol++;
else now = i;
}
if (tol > m) return false;
return true;
}
int main()
{
cin >> d >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
a[n + 1] = d;
int l = 0, r = d + 1, ans;
while (l < r)
{
int mid = l + r >> 1;
if (judge(mid)) l = mid + 1;
else r = mid;
}
cout << l - 1 << endl;
return 0;
}