# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239499 | frodakcin | Watching (JOI13_watching) | C++11 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
template<typename T> bool ckmax(T& a, T b){return a<b?a=b,1:0;}
template<typename T> bool ckmin(T& a, T b){return a>b?a=b,1:0;}
const int MN = 2e3+10;
int N, P, Q, dp[MN][MN], a[MN], nex[MN][2];
bool test(int w)
{
nex[N][0] = nex[N][1] = 0;
for(int i=0;i<N;++i)//can be optimized from O(N log N) to O(N) but it isnt bottleneck
{
nex[i][0] = std::lower_bound(a, a+N, a[i]+w )-a;
nex[i][1] = std::lower_bound(a, a+N, a[i]+w*2)-a;
}
memset(dp, -1, sizeof dp);
dp[0][0]=0;
for(int i=0;i<=P;++i)
for(int j=0;j<=Q;++j)
if(~dp[i][j])
{
int x=dp[i][j];
if(x==N) return 1;
if(i<P) ckmax(dp[i+1][j], nex[x][0]);
if(j<Q) ckmax(dp[i][j+1], nex[x][1]);
}
return 0;
}
int main()
{
scanf("%d%d%d", &N, &P, &Q);
for(int i=0;i<N;++i) scanf("%d", a+i);
std::sort(a, a+N);
if(P+Q>=N) return printf("1\n"),0;
int l=0,r=1e9,m;
for(;r-l>1;)
{
m=l+(r-l)/2;
if(test(m))
r=m;
else
l=m;
}
printf("%d\n", r);
return 0;
}