nm的nlogn的时复都能超,数据才10万啊喂!!!而且这是二分啊!
这是代码,求大佬解答%%%
#include<bits/stdc++.h>
using namespace std;
int n,c,d[100001];
bool check(int x){
int tot=0,prec=1;
for(int i=1;i<=n;i++)
if(d[i]-d[prec]>=x) tot++;
return tot>=c;
}
int main(){
cin>>n>>c;
for(int i=1;i<=n;i++) cin>>d[i];
sort(d+1,d+n+1);
int l=1,r=n;
while(l<r){
int mid=(l+r)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}cout<<l;
return 0;
}