Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<algorithm>
- using namespace std;
- int main() {
- // your code goes here
- int t;
- cin >> t;
- while( t-- ){
- long barn , cow;
- scanf("%ld%ld", &barn ,&cow );
- long stalls[barn];
- for( int i = 0; i < barn; i++ ){
- scanf("%ld", &stalls[i] );
- }
- long ans = 1;
- sort( stalls , stalls + barn );
- long int low = 1 , high = 1000000001;
- while( low <= high ){
- long int start = stalls[0] , c = 1;
- long int mid = low + ( high - low ) / 2;
- for( int i = 1; i < barn; i++ ){
- if( stalls[i] - start >= mid ){
- c++;
- start = stalls[i];
- }
- }
- if( c < cow ){
- high = mid - 1;
- }
- else{
- ans = mid;
- low = mid + 1;
- }
- }
- printf("%ld\n", ans );
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment