Submission #13361

#TimeUsernameProblemLanguageResultExecution timeMemory
13361gs14004Watching (JOI13_watching)C++14
50 / 100
1000 ms16876 KiB
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n,p,q,a[2005];
int nxt[2005], nxt2[2005];

int dp[2005][2005];

int f(int y, int z){
    if(y == p && z == q) return 0;
    if(~dp[y][z]) return dp[y][z];
    int ret = 0;
    if(y != p) ret = max(ret,nxt[f(y+1,z)]);
    if(z != q) ret = max(ret,nxt2[f(y,z+1)]);
    return dp[y][z] = ret;
}

bool trial(int x){
    for (int i=0; i<n; i++) {
        nxt[i] = (int)(lower_bound(a,a+n,a[i]+x) - a);
        nxt2[i] = (int)(lower_bound(a,a+n,a[i]+2*x) - a);
    }
    nxt[n] = nxt2[n] = n;
    memset(dp,-1,sizeof(dp));
    return f(0,0) >= n;
}

int main(){
    scanf("%d %d %d",&n,&p,&q);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    p = min(p,n);
    q = min(q,n);
    sort(a,a+n);
    int s = 0, e = 5e8;
    while (s != e) {
        int m = (s+e)/2;
        if(trial(m)) e = m;
        else s = m+1;
    }
    printf("%d",s);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...