求解
查看原帖
求解
275523
kingdomm楼主2020/5/15 21:33
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[10011];
int main()
{
	ll i,j;
	ll n,m;
	ll ans=0,k,q;
	ll L,R,mid;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	cin>>a[i];
	L=1;
	R=a[n]-a[1];
	while(L<=R){
		mid=(L+R)/2;
		q=a[1];
		k=0;
		for(i=1;i<=n;i++){
			if(a[i]-q>=mid){
				q=a[i];
				k++;
			}
		}
		if(k>=m){
			L=mid+1;
		}
		else{
			R=mid-1;
			ans=mid;
		}
	}
	cout<<ans;
	return 0;
}

为什么错???

2020/5/15 21:33
加载中...