愤怒的牛

数组开小 

#include
#include
#include
#include
#define ll long long
using namespace std;
ll n,m,x[100050],b[100050],ans;
inline long long judge(long long a){
	memset(b,0,sizeof(b));
	long long sum=1;
	b[sum]=x[1];
	for(int i=2;i<=n;i++){
		if(x[i]-b[sum]>=a){
			sum++;
			b[sum]=x[i];
		}
	}
	if(sum=m) return 0;
}
int main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x[i]);
	}
	sort(x+1,x+n+1);
	ll l=0,r=x[n]-x[1];
	ll mid; 
	while(l<=r){
		mid=(l+r)/2;
		if(!judge(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%lld",ans);
	return 0;
} 

 

你可能感兴趣的:(编程)