求助全紫
查看原帖
求助全紫
1382411
cxhhhhh楼主2024/8/15 22:02

rt,试了很多次

#include<bits/stdc++.h>
#define int long long
using namespace std;
int ll,n,k;
const int N=1e6+10;
int a[N];
int head,tail; 
bool check(int dis)//dis代表空旷值 
{
	int now=0,ans=0;int ff;
	while(now<ll)
	{
		
		if(head!=tail)ff=a[head];
		if(now+dis>=ff)
		{	
		now=ff;
		head++;
		}
		else
		{
			ans++;
			now+=dis;
		}
	}
	if(ans<=k)return true;
	return false;
}
signed main()
{
	cin>>ll>>n>>k;
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	tail=n+1,head=1;
	int l=1,r=ll;//二分空旷值 
	while(l<r)
	{
		int mid=l+r>>1;
		if(check(mid))r=mid;
		else l=mid+1;
		//cout<<mid<<endl;
	}
	cout<<l<<endl;
	return 0;
}
2024/8/15 22:02
加载中...