#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+1);
for(int i = 1;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));
bool good = false;
for(int i = 0;i<=P;++i){
for(int j = 0;j<=Q;++j){
if(i >= 1){
int it = upper_bound(arr.begin(),arr.end(),arr[dp[i-1][j]+1]+w-1)-arr.begin()-1;
dp[i][j] = max(dp[i][j],it);
}
if(j >= 1){
int it2 = upper_bound(arr.begin(),arr.end(),arr[dp[i][j-1]+1]+2*w-1)-arr.begin()-1;
dp[i][j] = max(dp[i][j],it2);
}
if(dp[i][j] >= N){
good = true;
}
}
}
if(good){
hi = w;
}
else{
lo = w+1;
}
}
cout << lo << "\n";
return 0;
}
# |
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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
428 KB |
Output is correct |
4 |
Correct |
1 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 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
62 ms |
892 KB |
Output is correct |
9 |
Correct |
57 ms |
880 KB |
Output is correct |
10 |
Correct |
104 ms |
1208 KB |
Output is correct |
11 |
Correct |
174 ms |
1160 KB |
Output is correct |
12 |
Correct |
577 ms |
4264 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |