P2678 [NOIP2015 提高组] 跳石头 二分 + 双指针
作者:
多米尼克領主的致意
,
2024-05-05 14:24:24
,
所有人可见
,
阅读 3
cd:
#include<bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
int len, n, k;
int a[N];
bool check(int x)
{
int cnt = 0;
for(int i = 0, j = 1;i <= n + 1;i++)
{
int li = 0;
while(a[i] + x > a[j] && j <= n + 1)
{
cnt++;
// if(x == 9)cout << a[j] <<
j++;
li++;
}
j++;
i += li;
}
// if(x == 9)
// cout << cnt << endl;
if(cnt > k)return false;
return true;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> len >> n >> k;
for(int i = 1;i <= n;i++)cin >> a[i];
a[n + 1] = len;
int l = 1, r = len;
while(l < r)
{
int mid = (l + r + 1) >> 1;
if(check(mid))l = mid;
else r = mid - 1;
}
cout << l;
return 0;
}