跳石头(二分)
思路:二分中:最小值最大化问题。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
inline void read(int &x){
x=0;int w=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
for(;ch>='0'&&ch<='9';ch=getchar())
x=(x<<3)+(x<<1)+(ch&15);
x*=w;
}
int L,n,m,a[N];
bool check(int x){
int pre=0,cnt=0;
for(int i=1;i<=n;i++){
if(a[i]-a[pre]<x)cnt++;
else pre=i;
}
return cnt<=m;
}
int main(){
read(L),read(n),read(m);
for(reg int i=1;i<=n;i++)
read(a[i]);
a[++n]=L;
int l=1,r=L;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) l=mid+1;
else r=mid-1;
}
printf("%d\n",r);
return 0;
}