Submission #867847

#TimeUsernameProblemLanguageResultExecution timeMemory
867847hungntWatching (JOI13_watching)C++14
100 / 100
151 ms16176 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 2002;

int n, a, b;
int p[N], dp[N][N];

bool check(int w)
{
    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int j1 = upper_bound(p + 1, p + n + 1, p[i] - w) - p - 1;
        int j2 = upper_bound(p + 1, p + n + 1, p[i] - 2 * w) - p - 1;
        for(int k = 0; k <= a; k++)
        {
            if(k) dp[i][k] = min(dp[i][k], dp[j1][k - 1]);
            dp[i][k] = min(dp[i][k], dp[j2][k] + 1);
        }
    }
    for(int i = 0; i <= a; i++)
        if(dp[n][i] <= b) return 1;
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++) cin >> p[i];
    if(n <= a + b) return cout << 1, 0;
    sort(p + 1, p + n + 1);
    int l = 2, r = 1000000000, mid, ans = r;
    while(l <= r)
    {
        mid = (l + r) >> 1;
        if(check(mid))
        {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...