Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

552K 110ms

Posted by KatrineYang at 2016-11-07 00:03:54 on Problem 2456
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int p[100005];
int N,C,m=2147483647;
bool k(int M){
	int cur = 0, gs = 1;
	while(cur < N){
		int next = cur+1;
		while(next < N && p[next]-p[cur]<m) next++;
		if(next >= N)break;
		cur = next;
		gs++;
		if(gs >= C)break;
	}
	return gs>=C;
}
int main() {
	scanf("%d%d",&N,&C);
	for(int i = 0; i < N; i++){
		scanf("%d",&p[i]);
	}
	sort(p,p+N);
	for(int i = 0; i < N-1; i++){
		if(p[i+1]-p[i]<m) m=p[i+1]-p[i];
	}
	int u = (int)((p[N-1]-p[0])*1.0/(C-1)), l=m;
	while(u>l){
		m=(u+l+1)/2;
		if(k(m)) l=m;
		else u=m-1;
	}
	printf("%d\n",l);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator