警示后人
查看原帖
警示后人
1304256
xy_mc楼主2024/11/30 15:31

check里的n千万补药写成L!!!!!

#include<bits/stdc++.h>
#define fastest ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
using namespace std;
int L,n,k,a[100005],ans; 
bool check(int x){
	int cnt=0;
	for(int i=1;i<=n;i++){
		int p=a[i]-a[i-1];
		if(p>x) cnt+=(p-1)/x;
	}
	return cnt<=k;
}
int main(){
	fastest;
	cin>>L>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int l=1,r=L;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}else{
			l=mid+1;
		}
	}
	cout<<ans;
	return 0;
}
2024/11/30 15:31
加载中...