Submission #90055

#TimeUsernameProblemLanguageResultExecution timeMemory
90055mra2322001Watching (JOI13_watching)C++14
100 / 100
325 ms16972 KiB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 2002;

int n, small, big, a[N], f[N][N], d1[N], d2[N];

bool check(int x){
    f1(i, n){
        d1[i] = lower_bound(a + 1, a + n + 1, a[i] - x + 1) - a;
        d2[i] = lower_bound(a + 1, a + n + 1, a[i] - 2*x + 1) - a;
    }
    memset(f, 0x3f3f3f, sizeof(f));
    f0(j, small + 1) f[0][j] = 0;
    f1(i, n){
        f0(j, small + 1){
            /// dung 1 small
            if(j > 0) f[i][j] = f[d1[i] - 1][j - 1];
            f[i][j] = min(f[i][j], f[d2[i] - 1][j] + 1);
        }
    }
    return f[n][small] <= big;
}

int main(){
    ios_base::sync_with_stdio(0);
 
    cin >> n >> small >> big;
    f1(i, n) cin >> a[i];
    if(small + big >= n){
        cout << 1; return 0;
    }
    sort(a + 1, a + n + 1);

    int l = 1, r = 1e9 + 1, ans = r;
    while(l <= r){
        int mid = (l + r)/2;
        if(check(mid)) r = mid - 1, ans = mid;
        else l = mid + 1;
    }
    cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...