Submission #1322040

#TimeUsernameProblemLanguageResultExecution timeMemory
1322040i_love_springWatching (JOI13_watching)C++20
50 / 100
1094 ms3384 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array
#define all(x) x.begin(), x.end()

const int inf = 2e9 + 5;

void solve() {
    int n, p, q;
    cin >> n >> p >> q;
    vector<int> a(n);
    for (int i = 0; i < n;i++) 
        cin >> a[i];
    
    if (p + q >= n)
        return (void)(cout << 1); 

    // a.insert(a.begin(), 0);
    a.push_back(0);
    sort(a.begin(), a.end());
    
    vector dp(n + 1, vector(p + 1, vector(q + 1, inf)));
    dp[0][0][0] = 0;
    
    for (int i = 1; i <= n;i++) {
        for (int j = 0; j <= p;j++) {
            for (int k = 0; k <= q;k++) {
                for (int f = 0; f < i;f++) {
                    if (j > 0) 
                        dp[i][j][k] = min(dp[i][j][k], max(dp[f][j - 1][k], 2 * (a[i] - a[f + 1] + 1)));
                    
                    if (k > 0) 
                        dp[i][j][k] = min(dp[i][j][k], max(dp[f][j][k - 1], a[i] - a[f + 1] + 1));
                }
            }
        }
    }

    int ans = inf;
    for (int i = 0; i <= p;i++) {
        for (int j = 0; j <= q;j++) 
            ans = min(ans, dp[n][i][j]);
    }


    // cout << ans << " ";

    cout << (ans + 1) / 2;

} 

signed main() {
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }
    return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...