이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, u, v) for (int i = u; i <= v; i++)
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define ll long long
#define N 2005
#define maxc 1000000007
using namespace std;
int dp[N][N];
int n, P, Q;
vector<int> a;
bool check(int len) {
    memset(dp, 60, sizeof dp);
    dp[0][0] = 0;
    FOR(i, 1, n)
    {
        int x1 = a[i] - len + 1;
        int pos1 = lower_bound(a.begin(), a.end(), x1) - a.begin() - 1;
        int x2 = a[i] - 2*len + 1;
        int pos2 = lower_bound(a.begin(), a.end(), x2) - a.begin() - 1;
        FOR(j, 0, P) {
            if (j) dp[i][j] = min(dp[i][j], dp[pos1][j-1]);
            dp[i][j] = min(dp[i][j], dp[pos2][j] + 1);
        }
    }
    FOR(j, 0, P)
        if (dp[n][j] <= Q) return 1;
    return 0;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("INP.TXT", "r", stdin);
    cin >> n >> P >> Q;
    if (P + Q >= n) {
        cout <<1;
        return 0;
    }
    FOR(i, 1, n) {
        int x; cin >> x;
        a.PB(x);
    }
    a.PB(-2*maxc);
    sort(a.begin(), a.end());
    int L = 0, R = maxc;
    while (R - L > 1) {
        int mid = (R + L)/2;
        if (check(mid)) R = mid;
        else L = mid;
    }
    cout <<R;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |