标签:style blog class code c java
//#define LOCAL #include<cstdio> #include<algorithm> using namespace std; int const MAX_N=100001; int const INF=10000000; int N,M,x[MAX_N]; void init() { for(int i=0;i<N;i++) { scanf("%d",&x[i]); } } // bool C(int d) { int last=0; for(int i=1;i<M;i++) { int crt=last+1; while(crt<N&&x[crt]-x[last]<d) { crt++; } if(crt==N) return false; last=crt; } return true; } void solve() { // std::sort(x,x+N); int lb=0,ub=INF; while(ub-lb>1) { int mid=(lb+ub)/2; if(C(mid)) lb=mid; else ub=mid; } printf("%d\n",lb); } int main() { #ifdef LOCAL freopen("1.in","r",stdin); freopen("1.out","w",stdout); #endif while(~scanf("%d%d",&N,&M)) { init(); solve(); } return 0; }
标签:style blog class code c java
原文地址:http://www.cnblogs.com/jianfengyun/p/3734902.html