fork(11) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int N,C;
  4. long long A[100005];
  5. bool chk(long long dist)
  6. {
  7. long long last=A[0];
  8. int cnt=1;
  9. for(int i=1; i<N; i++){
  10. if((A[i]-last)>=dist){
  11. cnt++;
  12. last=A[i];
  13. }
  14. }
  15. if(cnt>=C)return true;
  16. return false;
  17. }
  18. void solve()
  19. {
  20. cin>>N>>C;
  21. for(int i=0; i<N; i++)cin>>A[i];
  22. sort(A,A+N);
  23. long long low=0; long long high = 1000000000;
  24. int mid; int pos=0;
  25. while(high>=low)
  26. {
  27. mid=(high+low)/2;
  28. if(chk(mid)){
  29. low=mid+1;
  30. pos=mid;
  31. }
  32. else{
  33. high = mid-1;
  34. }
  35. }
  36. cout<<pos<<endl;
  37. }
  38. int main()
  39. {
  40. int T;
  41. cin>>T;
  42. while(T--)solve();
  43. return 0;
  44. }
Success #stdin #stdout 0s 16848KB
stdin
Standard input is empty
stdout
Standard output is empty