|
- #include<iostream>
- #include<algorithm>
- using namespace std;
- int n,c,l,r;
- int a[100001];
- int mid,ans,cnt,s,x;
- int main()
- {
- cin>>n>>c;
- for(int i=1;i<=n;i++)cin>>a[i];
- sort(a+1,a+n+1);
- r=a[n]-a[1];
- while(l<=r)
- {
- mid=l+r>>1;
- s=x=1;
- cnt=0;
- while(x<n)
- {
- x++;
- if(a[x]-a[s]<mid)cnt++;
- else s=x;
- }
- if(cnt+c<=n)
- {
- ans=mid;
- l=mid+1;
- }
- else r=mid-1;
- }
- cout<<ans;
- return 0;
- }
复制代码 |
|