求助,0
查看原帖
求助,0
793625
Pink_Cut_Tree楼主2023/8/10 14:52
#include<iostream>
#include<algorithm>
using namespace std;
int L,N,K,place[100006];
bool check(int x){
	if(K<=0){
		return 0;
	}
	int ans=0,lasth=0;
	for(int i=1;i<=N;i++){
		if(i==1){
			while(lasth+x<=place[1]){
				lasth+=x; ans++;
			}
		}
		else if(i==N){
			lasth=place[N]+x;
			while(lasth<=L){
				lasth+=x; ans++;
			}
		}
		else{
			if(place[i]<=lasth+x&&lasth+x<=place[i+1]){
				lasth=place[i]+x; ans++;
			}
			while(place[i]<=lasth+x&&lasth+x<=place[i+1]){
				lasth+=x; ans++;
			}
		}
	}
return ans>=K;
}
int main(){
	cin>>L>>N>>K;
	for(int i=1;i<=N;i++){
		cin>>place[i];
	}
	sort(place+1,place+N+1);
	int l=1,r=L,ans,mid;
	while(l<=r){
		mid=((r-l)>>1)+l;
		if(check(mid)){
			l=mid+1,ans=mid;
		}
		else{
			r=mid-1;
		}
	}
	cout<<ans;
return 0;
}
2023/8/10 14:52
加载中...