不知道哪里错了,30分,求助大佬
查看原帖
不知道哪里错了,30分,求助大佬
582113
xuan132楼主2022/1/10 16:42
#include <iostream>
using namespace std;
#define ll long long
#define maxn 50007
ll a[maxn],L; 
int n,m;
ll judge(ll x)
{
	bool h[maxn]={false};
	ll tot=0;
	for(int i=0;i<=n;i++)
	{
		if(h[i])continue;
		ll b=i+1;
		while(h[b])b++;
		if(a[b]-a[i]<x&&b!=n+1)tot++,h[b]=true;
	}
	return tot;
}
int main()
{
	cin>>L>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	a[n+1]=L;
	ll start=0,mid,end=L;
	while(start<=end)
	{
		mid=(start+end)>>1;
		if(judge(mid)>m)
		{
			end=mid-1;
		}
		else if(judge(mid)<=m)
		{
			start=mid+1;
		}
	}
	cout<<mid;
	return 0;
}
2022/1/10 16:42
加载中...