# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107687 | maruii | Watching (JOI13_watching) | C++14 | 143 ms | 8704 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 <bits/stdc++.h>
using namespace std;
int N, P, Q;
unsigned int A[2002], X[2002], Y[2002];
int dp[2001][2001];
int f(int w){
for(int i=0; i<=N; ++i){
X[i] = lower_bound(A+i+1, A+N+1, A[i+1]+w) - A - 1;
Y[i] = lower_bound(A+i+1, A+N+1, A[i+1]+(w<<1)) - A - 1;
}
for(int i=0; i<=P; ++i){
for(int j=0; j<=Q; ++j){
if(i && j) dp[i][j] = max(X[dp[i-1][j]], Y[dp[i][j-1]]);
else if(i) dp[i][j] = X[dp[i-1][j]];
else if(j) dp[i][j] = Y[dp[i][j-1]];
}
}
return dp[P][Q];
}
int main(){
ios_base::sync_with_stdio(0), cin.tie(0);
cin>>N>>P>>Q;
for(int i=1; i<=N; ++i) cin>>A[i];
sort(A+1, A+N+1);
A[N+1] = 2e9;
Q = min(Q, N), P = min(P, N-Q);
int l=1, r=1e9;
while(l<r){
int m = l+r>>1;
if(f(m) == N) r = m;
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |