Guest User

Untitled

a guest
Oct 18th, 2018
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int t;
  8. cin >> t;
  9. while( t-- ){
  10. long barn , cow;
  11. scanf("%ld%ld", &barn ,&cow );
  12. long stalls[barn];
  13. for( int i = 0; i < barn; i++ ){
  14. scanf("%ld", &stalls[i] );
  15. }
  16. long ans = 1;
  17. sort( stalls , stalls + barn );
  18. long int low = 1 , high = 1000000001;
  19. while( low <= high ){
  20. long int start = stalls[0] , c = 1;
  21. long int mid = low + ( high - low ) / 2;
  22. for( int i = 1; i < barn; i++ ){
  23. if( stalls[i] - start >= mid ){
  24. c++;
  25. start = stalls[i];
  26. }
  27. }
  28. if( c < cow ){
  29. high = mid - 1;
  30. }
  31. else{
  32. ans = mid;
  33. low = mid + 1;
  34. }
  35. }
  36. printf("%ld\n", ans );
  37. }
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment