奇怪
查看原帖
奇怪
1068809
SpringNeverDie楼主2024/7/23 21:03

把a数组的大小改为50001就有50,不改就只有40

#include<bits/stdc++.h>
using namespace std;

int M,N,cnt;

long long L,a[60001],zuo,you,zhong,ans;

bool check(long long x){
	long long xx=0,str=0;
	for(int i=1;i<=N+1;i++){
		if(a[i]-a[str]<x) xx++;
		else str=i;
	}
	if(xx>M) return 0;
	else return 1;
}

int main(){
	//freopen("P2678.txt","r",stdin);
	cin >> L >> N >> M;
	
	if(N==0){
		cout << L;
		return 0;
	}
	
	zuo=0;
	you=1e9+10;
	
	for(int i=1;i<=N;i++) cin >> a[i];
	
	while(zuo<=you){
		zhong=(zuo+you)/2;
		if(check(zhong)){
			zuo=zhong+1;
			ans=zhong;
		}else{
			you=zhong-1;
		}
	} 
	cout << ans;
}
2024/7/23 21:03
加载中...