Submission #1341270

#TimeUsernameProblemLanguageResultExecution timeMemory
1341270Born_To_LaughWatching (JOI13_watching)C++17
0 / 100
2 ms344 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;
const int maxn = 2010;
int n, p, q;
int a[maxn];

int check(int w){
    vector<vector<int>> dp(p + 2, vector<int> (q + 2, 0));
    vector<vector<int>> cost(n + 1, vector<int> (2, 0));
    
    int l = 0;
    for(int r = 1; r <= n; ++r){
        while(a[r] - a[l + 1] + 1 > w) l++;
        cost[l][0] = max(cost[l][0], r - l);
    }

    l = 0;
    for(int r = 1; r <= n; ++r){
        while(a[r] - a[l + 1] + 1 > 2 * w) l++;
        cost[l][1] = max(cost[l][1], r - l);
    }


    for(int i=0; i<=p; ++i){
        for(int j=0; j<=q; ++j){
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + cost[dp[i][j]][0]);
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + cost[dp[i][j]][1]);
        }
    }
    if(dp[p][q] == n) return 1;
    return 0;
}
void solve(){
    cin >> n >> p >> q;
    for(int i=1; i<=n; ++i) cin >> a[i];
    if(p + q >= n){
        cout << 1 << '\n';
        return;
    }
    int lo = 1, hi = INF;
    int ans = hi;
    // check(4);
    while(hi >= lo){
        int mid = (lo + hi) >> 1;
        if(check(mid)){
            ans = mid;
            hi = mid - 1;
        }
        else lo = mid + 1;
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...