Advertisement
Saleh127

Spoj AGGRCOW

Jul 22nd, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9. test
  10. {
  11. ll a[200000],n,x,c,lo=0,hi=1e9+1,ans=1,mid,i,j;
  12. cin>>n>>x;
  13. for(i=0;i<n;i++)
  14. {
  15. cin>>a[i];
  16. }
  17. sort(a,a+n);
  18. while(lo<=hi)
  19. {
  20. mid=(lo+hi)/2;
  21. c=1;
  22. j=0;
  23. for(i=1;i<n;i++)
  24. {
  25. if(a[i]-a[j]>=mid)
  26. {
  27. c++;
  28. j=i;
  29. }
  30. }
  31. if(c>=x)
  32. {
  33. ans=mid;
  34. lo=mid+1;
  35. }
  36. else hi=mid-1;
  37. }
  38. cout<<ans<<endl;
  39. }
  40.  
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement