제출 #1336887

#제출 시각아이디문제언어결과실행 시간메모리
1336887kawhiet구경하기 (JOI13_watching)C++20
100 / 100
147 ms16240 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, p, q;
    cin >> n >> p >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ranges::sort(a);
    p = min(p, n);
    q = min(q, n);
    auto good = [&](int k) {
        vector<vector<int>> dp(p + 1, vector<int>(q + 1));
        dp[0][0] = 0;
        for (int i = 0; i <= p; i++) {
            for (int j = 0; j <= q; j++) {
                int s = dp[i][j] + 1;
                if (s >= n + 1) {
                    return true;
                }
                if (i < p) {
                    int pos = s;
                    while (pos <= n && a[pos] - a[s] < k) {
                        pos++;
                    }
                    dp[i + 1][j] = max(dp[i + 1][j], pos - 1);
                }
                if (j < q) {
                    int pos = s;
                    while (pos <= n && a[pos] - a[s] < 2 * k) {
                        pos++;
                    }
                    dp[i][j + 1] = max(dp[i][j + 1], pos - 1);
                }
            }
        }
        return false;
    };
    int l = 0, r = 1e9 + 1;
    while (l + 1 < r) {
        int m = (l + r) / 2;
        if (good(m)) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...