【题解】
二分答案+贪心check.
1 #include2 #include 3 #include 4 #define LL long long 5 #define rg register 6 #define N 200010 7 using namespace std; 8 int n,m,a[N],l,r,mid; 9 inline int read(){10 int k=0,f=1; char c=getchar();11 while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();12 while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();13 return k*f;14 }15 inline bool check(){16 int sum=1,last=a[1];17 for(rg int i=2;i<=n;i++)if(a[i]-last>=mid){18 sum++;19 last=a[i];20 }21 // printf("mid=%d sum=%d\n",mid,sum);22 return sum>=m;23 }24 int main(){25 n=read(); m=read();26 for(rg int i=1;i<=n;i++) a[i]=read();27 sort(a+1,a+1+n);28 l=0; r=a[n]-a[1]+1;29 while(l+1 >1;31 if(check()) l=mid; else r=mid;32 }33 printf("%d\n",l);34 return 0;35 }