50分求调(调完必关)
查看原帖
50分求调(调完必关)
1002181
Tom518楼主2025/7/22 16:59
#include<bits/stdc++.h>
using namespace std;
#define int long long
int d,n,m,a[50010],l,r,ans;
bool pd(int x){
	int now=0;
	int i=0;
	int tot=0;
	while(i<n+1){
		i++;
		if(a[i]-a[now]<x){
			tot++;
		}
		else{
			now=i;
		}
	}
	if(tot<=m){
		return 1;
	}
	if(tot>m){
		return 0;
	}
}
signed main(){
	cin>>d>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	a[n+1]=d;
	l=1,r=d;
	while(l<r){
		int mid=(l+r)/2;
		if(pd(mid)==1){
			ans=mid; 
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

2025/7/22 16:59
加载中...