제출 #1348885

#제출 시각아이디문제언어결과실행 시간메모리
1348885mozkun구경하기 (JOI13_watching)C++20
100 / 100
117 ms16296 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, p, q;
    cin >> n >> p >> q;

    vector<ll> a(n + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];

    sort(a.begin() + 1, a.end());

    p = min(p, n);
    q = min(q, n);

    auto good = [&](ll k){
        vector<vector<int>> dp(p + 1, vector<int>(q + 1, 0));

        for(int i = 0; i <= p; i++){
            for(int j = 0; j <= q; j++){
                int s = dp[i][j] + 1;
                if(s > n) 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;
    };

    ll l = 0, r = 1e9 + 1;
    while(l + 1 < r){
        ll mid = (l + r) >> 1;
        if(good(mid)) r = mid;
        else l = mid;
    }

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