Submission #1051024

#TimeUsernameProblemLanguageResultExecution timeMemory
1051024dpsaveslivesWatching (JOI13_watching)C++17
100 / 100
577 ms4264 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N,P,Q; cin >> N >> P >> Q;
    vector<int> arr(N+1);
    for(int i = 1;i<=N;++i) cin >> arr[i];
    if(P+Q >= N){
        cout << 1 << "\n";
        return 0;
    }
    sort(arr.begin(),arr.end());
    int lo = 0, hi = 1e9;
    while(lo < hi){
        int w = lo+(hi-lo)/2;
        vector<vector<int>> dp(P+1,vector<int>(Q+1,0));
        bool good = false;
        for(int i = 0;i<=P;++i){
            for(int j = 0;j<=Q;++j){
                if(i >= 1){
                    int it = upper_bound(arr.begin(),arr.end(),arr[dp[i-1][j]+1]+w-1)-arr.begin()-1;
                    dp[i][j] = max(dp[i][j],it);
                }
                if(j >= 1){
                    int it2 = upper_bound(arr.begin(),arr.end(),arr[dp[i][j-1]+1]+2*w-1)-arr.begin()-1;
                    dp[i][j] = max(dp[i][j],it2);
                }
                if(dp[i][j] >= N){
                    good = true;
                }
            }
        }
        if(good){
            hi = w;
        }
        else{
            lo = w+1;
        }
    }
    cout << lo << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...