#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 2e3 + 5;
int32_t main(){
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
int n, p, q;
cin>>n>>p>>q;
p = min(p, n);
q = min(q, n);
vector<int> a(n);
for(int i = 0; i < n; i++){
cin>>a[i];
}
sort(a.begin(), a.end());
if(p + q >= n){
cout<<1<<endl;
return 0;
}
vector<int> sm(N), bg(N);
vector<vector<int> > dp(p+1, vector<int>(q+1, 0));
int l = 1, r = inf + 5;
while(l < r){
int m = (l + r)/2;
for(int i = 0; i <= p; i++){
for(int j = 0; j <= q; j++){
dp[i][j] = 0;
}
}
int x = 0;
for(int i = 0; i < n; i++){
while(x < n && a[x] - a[i] + 1 <= m) x++;
sm[i] = x;
}
sm[n] = n;
x = 0;
for(int i = 0; i < n; i++){
while(x < n && a[x] - a[i] + 1 <= m * 2) x++;
bg[i] = x;
}
bg[n] = n;
for(int s = p + q - 1; s >= 0; s--){
for(int small = p; small >= 0; small--){
int big = s - small;
if(big < 0 || big > q) continue;
if(small < p) dp[small][big] = max(dp[small][big], sm[dp[small+1][big]]);
if(big < q) dp[small][big] = max(dp[small][big], bg[dp[small][big+1]]);
}
}
if(dp[0][0] == n) r = m;
else l = m + 1;
}
cout<<l<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
13 ms |
1112 KB |
Output is correct |
9 |
Correct |
29 ms |
1112 KB |
Output is correct |
10 |
Correct |
109 ms |
1880 KB |
Output is correct |
11 |
Correct |
21 ms |
1624 KB |
Output is correct |
12 |
Correct |
164 ms |
8072 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |