Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n;
- int c;
- vi places;
- cin >> n >> c;
- FORI(n) {
- int input;
- cin >> input;
- places.push_back(input);
- }
- sort(places.begin(), places.end());
- int low = 1;
- int high = places[n - 1];
- while (low < high) {
- int mid = (high + low) / 2;
- bool suceed = true;
- int next = 0;
- FORI (c - 1) {
- int fb = -1;
- for (int i = next + 1; i < n; i++) {
- if (places[i] >= places[next] + mid) {
- fb = i;
- break;
- }
- }
- if (fb == -1) {
- suceed = false;
- break;
- }
- next = fb;
- }
- if (suceed)
- low = mid + 1;
- else
- high = mid;
- }
- cout << low - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement