Submission #1136149

#TimeUsernameProblemLanguageResultExecution timeMemory
1136149SharkyWatching (JOI13_watching)C++20
0 / 100
40 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

#define int long long
#define fi first
#define se second

const int N = 2001;
int n, a[N], P, Q;

bool check(int d) {
    int eff = min(Q, 2000LL);
    vector<vector<int>> dp(n+1, vector<int> (eff+1, 1e9));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        int lstq = 0, lstp = 0;
        for (int j = i - 1; j >= 0; j--) {
            lstq = j;
            if (a[j] + 2 * d <= a[i]) break;
        }
        for (int j = i - 1; j >= 0; j--) {
            lstp = j;
            if (a[j] + d <= a[i]) break;
        }
        for (int j = 0; j <= eff; j++) {
            if (j) dp[i][j] = min(dp[i][j], dp[lstq][j - 1]);
            dp[i][j] = min(dp[i][j], dp[lstp][j] + 1);
        }
    }
    // for (int j = 0; j <= eff; j++) debug(dp[n][j]);
    for (int j = 0; j <= eff; j++) if (dp[n][j] <= P) return true;
    return false;
}

void solve() {
    cin >> n >> P >> Q;
    a[0] = -1e18;
    for (int i = 1; i <= n; i++) cin >> a[i];
    sort(a + 1, a + n + 1);
    int l = 0, r = 1e9;
    while (l < r) {
        int mid = (l + r) / 2;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << '\n';
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int test = 1;
    // cin >> test;
    while (test--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...