제출 #102827

#제출 시각아이디문제언어결과실행 시간메모리
102827popovicirobertWatching (JOI13_watching)C++14
100 / 100
208 ms14184 KiB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

const ll INF = 1e15;
const int MAXN = 2005;

int dp[MAXN + 1][MAXN + 1];
ll arr[MAXN + 1];

int nxt_a[MAXN + 1], nxt_b[MAXN + 1];

inline bool check(ll w, int n, int a, int b) {
    int i, j;
    int pa = 0, pb = 0;
    for(i = 0; i <= n; i++) {
        while(arr[pa] - arr[i] < w) {
            pa++;
        }
        while(arr[pb] - arr[i] < 2LL * w) {
            pb++;
        }
        nxt_a[i] = pa;
        nxt_b[i] = pb;
    }
    dp[0][0] = 1;
    for(int s = 1; s <= a + b; s++) {
        for(i = 0; i <= min(a, s); i++) {
            j = s - i;
            if(j > b) {
                continue;
            }
            dp[i][j] = 0;
            if(i > 0) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j]);
                dp[i][j] = max(dp[i][j], nxt_a[dp[i - 1][j]]);
            }
            if(j > 0) {
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
                dp[i][j] = max(dp[i][j], nxt_b[dp[i][j - 1]]);
            }
            if(dp[i][j] == n + 1) {
                return 1;
            }
        }
    }
    return 0;
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> a >> b;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    arr[n + 1] = INF;
    a = min(n, a), b = min(b, n);
    int res = 0;
    for(int step = 1 << 29; step; step >>= 1) {
        if(check(res + step, n, a, b) == 0) {
            res += step;
        }
    }
    cout << res + 1;
    //cin.close();
    //cout.close();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...