fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(NULL);
  8. int t; cin >> t;
  9. while (t--) {
  10. int n, m;
  11. cin >> n>>m;
  12. vector<long long> a(n);
  13. for (int i =0;i<n;i++) cin>>a[i];
  14. sort(a.begin(), a.end());
  15. long long l=1,r=a.back()-a.front(), an=0;
  16. while (l<=r) {
  17. long long mid=(l+r)/2;
  18. int dem=1;
  19. long long la=a[0];
  20. for (int i=1;i<n;i++) {
  21. if (a[i]-la>=mid) {
  22. dem++;
  23. la=a[i];
  24. }
  25. }
  26. if (dem>=m) {
  27. an=mid;
  28. l=mid+1;
  29. } else {
  30. r=mid-1;
  31. }
  32. }
  33. cout <<an<<endl;
  34. }
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty