这是一道(DAY2 quad T1),总体来说思路不算难,但是需要维护,如果暴力搜索显然会爆炸,我们只需要用二分查找答案即可。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cctype>
using namespace std;
int l,n,m,ll,rr,mid,now,i,a[50005],s,ans;
#define scy(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int main(){
//scy("in");
l=read(),n=read(),m=read();
for(i=1;i<=n;i++){
a[i]=read();
} //输入
ll=0;rr=l;
while(ll<=rr){
mid=(rr+ll)/2;
now=0;s=0;
for(i=1;i<=n;i++){
if(a[i]-a[now]<mid)
s++;
else now=i;}
if(s<=m){
ans=mid;
ll=mid+1;
}
else rr=mid-1;
}
printf("%d",ans);
return 0;
}