# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
239499 | frodakcin | 구경하기 (JOI13_watching) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}