제출 #867267

#제출 시각아이디문제언어결과실행 시간메모리
867267KoyoteWatching (JOI13_watching)C++11
100 / 100
169 ms16216 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e3 + 2;
int n, a, b, x[maxN], dp[maxN][maxN];

inline bool binF(int searchVal) {
    memset(dp, 0x7f, sizeof(dp));
    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        int sw = 1, sw2 = 1;
        while (x[i] - x[sw] + 1 > searchVal) sw++;
        while (x[i] - x[sw2] + 1 > (searchVal << 1)) sw2++;
        for (int j = 0; j <= a; j++) {
            dp[i][j] = dp[sw2 - 1][j] + 1;
            if (j > 0) dp[i][j] = min(dp[i][j], dp[sw - 1][j - 1]);
        }
    }

    for (int i = 0; i <= a; i++) if (dp[n][i] <= b)
        return true;
    return false;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> a >> b;
    if (a + b >= n) return cout << 1 << '\n', 0;
    for (int i = 1; i <= n; i++) cin >> x[i];
    sort(x + 1, x + n + 1);

    int lo = 1, hi = int(1e9), ans = hi;
    while (lo <= hi) {
        int mid = (lo + hi) >> 1;
        if (binF(mid)) ans = mid, hi = mid - 1;
        else lo = mid + 1;
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...