Submission #1241658

#TimeUsernameProblemLanguageResultExecution timeMemory
1241658trantrungkeinWatching (JOI13_watching)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 5;
int n, P, Q, a[N];

bool check(int mid) {
    int i = 1;
    int p = P, q = Q;

    while (i <= n) {
        int j = i;
        while (j <= n && a[j] - a[i] <= mid - 1) j++;
        if (p > 0) {
            p--;
            i = j;
            continue;
        }

        j = i;
        while (j <= n && a[j] - a[i] <= 2 * mid - 1) j++;
        if (q > 0) {
            q--;
            i = j;
            continue;
        }

        return false;
    }

    return true;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> P >> Q;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1); 

    int l = 0, r = 1e9, ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...