http://poj.org/problem?id=2456
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=100005;
const int inf=0x3f3f3f3f;
int n,m;
int x[maxn];
bool check(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(){//二分找解,贪心验证
sort(x,x+n);
int lb=0,ub=inf;
while(ub-lb>1){
int mid=(lb+ub)/2;
if(check(mid)) lb=mid;
else ub=mid;
}
cout<<lb<<endl;
}
int main(){
while(cin>>n>>m){
for(int i=0;i<n;i++)
cin>>x[i];
solve();
}
return 0;
}