Submission #1328213

#TimeUsernameProblemLanguageResultExecution timeMemory
1328213qardashali구경하기 (JOI13_watching)C++20
100 / 100
23 ms8516 KiB
/**
 * Author: Qardashali
**/
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int MAXN = 2005;
int n, p, q;
int a[MAXN];
int next_s[MAXN], next_l[MAXN];
int dp[MAXN][MAXN];

bool check(int w){
    int ps = 0, pl = 0;
    for(int i = 0; i < n; i++){
        while(ps < n && a[ps] < (ll)a[i] + w){
            ps++;
        }
        next_s[i] = ps;
        while(pl < n && a[pl] < (ll)a[i] + 2LL * w){
            pl++;
        }
        next_l[i] = pl;
    }
    next_s[n] = n;
    next_l[n] = n;
    int lp = min(p, n);
    int lq = min(q, n);
    for(int i = 0; i <= lp; i++){
        for(int j = 0; j <= lq; j++){
            dp[i][j] = 0;
        }
    }
    for(int i = 0; i <= lp; i++){
        for(int j = 0; j <= lq; j++){
            if(i + j > n){
                break;
            }
            int cur = dp[i][j];
            if(cur == n){
                return true;
            }
            if(i < lp){
                if(next_s[cur] > dp[i + 1][j]){
                    dp[i + 1][j] = next_s[cur];
                }
            }
            if(j < lq){
                if(next_l[cur] > dp[i][j + 1]){
                    dp[i][j + 1] = next_l[cur];
                }
            }
        }
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> p >> q;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    if(p + q >= n){
        cout << 1 << '\n';
        return 0;
    }
    int l = 1, h = 1000000000, ans = 1000000000;
    while(l <= h){
        int mid = l + (h - l) / 2;
        if(check(mid)){
            ans = mid;
            h = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...