#include<bits/stdc++.h>
using namespace std;
const int MX = 2005;
int n, m;
vector<int>a;
vector<pair<int,int>>ins;
int dp[MX][MX];
int w;
int solve(int i, int can) {
if(i==m) return 0;
int &ret = dp[i][can];
if(ret!=-1) return ret;
ret = solve(i+1, can);
if(can==0) return ret;
int j = lower_bound(ins.begin(), ins.end(), make_pair(ins[i].second+2*w, INT_MIN))
-ins.begin();
ret = max(ret, j-i-1+solve(j, can-1));
return ret;
}
void PlayGround() {
int p, q;
cin >> n >> p >> q;
if(p+q>=n) {
cout << "1\n";
return;
}
for(int i=0; i<n; ++i) {
int x; cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
int l=1, r=1e9;
while(l<r) {
w = (l+r)/2;
ins = {};
for(int i=0, j; i<n; i=j) {
j = lower_bound(a.begin(), a.end(), a[i]+w) - a.begin();
ins.emplace_back(a[j-1], a[i]);
}
m = ins.size();
memset(dp, -1, sizeof dp);
int cnt = max(0, m-p-q);
if(solve(0, q)>=cnt) {
r = w;
} else {
l = w+1;
}
}
cout << l << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
16028 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
54 ms |
15948 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
56 ms |
16028 KB |
Output is correct |
8 |
Incorrect |
57 ms |
15948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
16076 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Incorrect |
65 ms |
16060 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |