90分求助
查看原帖
90分求助
1056929
leyitianzun楼主2025/6/18 20:27

WA了第一个点,代码如下:

#include<iostream>
using namespace std;
int q,w,e[100000001];
bool check(int x){
	int sum=0;
	for(int c=1;c<=q;c++){
		int len=e[c]-e[c-1];
		if(len%x==0)sum+=len/x-1;
		else{
			sum+=len/x;
		}
	}
	if(sum<=w+1){
		return true;
	}
	else return false;
}
int main(){
	cin>>q>>w;
	for(int c=1;c<=q;c++){
		cin>>e[c];
	}
	int lef=1,rig=e[q],ans=0;
	if(e[q]==1){
		cout<<1;
		return 0;
	}
	if(e[q]==2){
		if(q==1)cout<<2;
		else cout<<1;
		return 0;
	} 
	while(1){
		ans=(lef+rig)/2;
		if(rig-lef==2){
			break;
		}
		if(check(ans)==false){
			lef=ans;
		}else{
			rig=ans+1;
		}
	}
	cout<<ans;
}
2025/6/18 20:27
加载中...