Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
552K 110ms#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator