Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. int main(){
  2.     ios_base::sync_with_stdio(false);
  3.     cin.tie(NULL);
  4.  
  5.     int n;
  6.     int c;
  7.     vi places;
  8.     cin >> n >> c;
  9.  
  10.     FORI(n) {
  11.         int input;
  12.         cin >> input;
  13.         places.push_back(input);
  14.     }
  15.  
  16.     sort(places.begin(), places.end());
  17.  
  18.     int low = 1;
  19.     int high = places[n - 1];
  20.  
  21.     while (low < high) {
  22.         int mid = (high + low) / 2;
  23.         bool suceed = true;
  24.         int next = 0;
  25.  
  26.         FORI (c - 1) {
  27.             int fb = -1;
  28.             for (int i = next + 1; i < n; i++) {
  29.                 if (places[i] >= places[next] + mid) {
  30.                     fb = i;
  31.                     break;
  32.                 }
  33.             }
  34.  
  35.             if (fb == -1) {
  36.                 suceed = false;
  37.                 break;
  38.             }
  39.             next = fb;
  40.         }
  41.  
  42.         if (suceed)
  43.             low = mid + 1;
  44.         else
  45.             high = mid;
  46.     }
  47.     cout << low - 1;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement