fork download
  1. #include <bits/stdc++.h>
  2. #define ll unsigned long long int
  3. using namespace std;
  4. ll tc;
  5. ll n,c, x;
  6. vector<ll> a;
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
  10.  
  11. cin>>tc;
  12. while(tc--)
  13. {
  14.  
  15. cin>>n>>c;
  16.  
  17. for(int i=0;i<n;i++)
  18. {
  19. cin>>x;
  20. a.push_back(x);
  21. }
  22. sort(a.begin(),a.end());
  23. ll i=1,j=1000000001,ans=0,l=0;
  24. while(i<=j)
  25. {
  26. ll mid=((j+i)/2);
  27. ll fi=a[0],temp=1;
  28. for(int k=1;k<n;k++)
  29. {
  30. if(a[k]-fi>=mid)
  31. { temp++;
  32. fi=a[k];
  33. }
  34. }
  35. if(temp<c)
  36. j=mid-1;
  37. else
  38. {
  39. ans=mid;
  40. i=mid+1;
  41. }
  42. }
  43. cout<<ans<<endl;
  44. a.clear();
  45. }
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 5496KB
stdin
Standard input is empty
stdout
Standard output is empty