File size: 668 Bytes
c4b0eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <bits/stdc++.h>
using namespace std;
int n,c;
vector<int> a;
int f(int x){
int cows=1, lastpos=a[0];
for(int i=1;i<n;i++){
if(a[i]-lastpos >= x ){
cows++;
lastpos=a[i];
}
if(cows>=c) return 1;
}
return 0;
}
void solve(){
cin>>n>>c;
a.resize(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
int l=0, r=a[n-1]-a[0]+1,mid;
while(r-l>=1){
mid = (l+r)/2;
if(f(mid)==0) r=mid;
else l = mid;
}
cout<<l<<endl;
}
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
solve();
}
return 0;
|