fork(3) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. long long t,n,c;
  8. cin>>t;
  9. vector<long long> ans;
  10.  
  11. while(t--){
  12. cin>>n>>c;
  13. long long x[n];
  14. long long mind=LLONG_MAX;
  15. for(long long i=0;i<n;i++){
  16. cin>>x[i];
  17. mind=min(x[i],mind);
  18. }
  19. sort(x,x+n);
  20.  
  21. long long low=mind;
  22. long long high=x[n-1]-x[0];
  23. long long mid;
  24.  
  25. while(low < high){
  26. mid = low+(high-low+1)/2;
  27. long long cows=1;
  28. long long idx=0;
  29. for(long long i=1;i<n;i++){
  30. if(x[i]-x[idx] >= mid) {cows++; idx=i;}
  31. }
  32. if(cows >= c) low=mid;
  33. else high=mid-1;
  34. }
  35. ans.push_back(low);
  36. }
  37.  
  38. for(vector<long long>::iterator it=ans.begin();it!=ans.end();it++){
  39. cout<<*it<<endl;
  40. }
  41. return 0;
  42. }
  43.  
Runtime error #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
Standard output is empty