#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,P,Q; cin >> N >> P >> Q;
vector<int> arr(N);
for(int i = 0;i<N;++i) cin >> arr[i];
if(P+Q >= N){
cout << 1 << "\n";
return 0;
}
sort(arr.begin(),arr.end());
int lo = 0, hi = 1e9;
while(lo < hi){
int w = lo+(hi-lo)/2;
vector<vector<int>> dp(P+1,vector<int>(Q+1,0));
for(int i = 0;i<=P;++i){
for(int j = 0;j<=Q;++j){
int ind = dp[i][j];
if(i < P){
int it = lower_bound(arr.begin(),arr.end(),arr[ind]+w)-arr.begin();
dp[i+1][j] = max(dp[i+1][j],it);
}
if(j < Q){
int it2 = lower_bound(arr.begin(),arr.end(),arr[ind]+2*w)-arr.begin();
dp[i][j+1] = max(dp[i][j+1],it2);
}
}
}
if(dp[P][Q] >= N){
hi = w;
}
else{
lo = w+1;
}
}
cout << lo << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |