#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 2e3 + 5;
int a[N], n, p, q;
int dp[N][N], pw[N], p2w[N];
signed main(){
ios::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[0] = -2e9;
p = min(p, n), q = min(q, n);
auto check = [&](int w){
memset(dp, 127, sizeof dp);
memset(pw, -1, sizeof pw);
memset(p2w, -1, sizeof p2w);
for(int i=1;i<=n;i++){
for(int j=i-1;j>=0;j--){
if(a[i] - a[j] + 1 > w && pw[i] == -1) pw[i] = j;
if(a[i] - a[j] + 1 > 2 * w && p2w[i] == -1) p2w[i] = j;
}
}
for(int i=0;i<N;i++) dp[0][i] = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
if(j > 0) dp[i][j] = min(dp[i][j], dp[pw[i]][j - 1]);
dp[i][j] = min(dp[i][j], dp[p2w[i]][j] + 1);
}
}
return (dp[n][p] <= q);
};
int l = 1, r = 1e9;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
//~ cout<<check(l)<<" ";
cout<<l<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
16056 KB |
Output is correct |
2 |
Correct |
55 ms |
16048 KB |
Output is correct |
3 |
Incorrect |
53 ms |
16060 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
16076 KB |
Output is correct |
2 |
Correct |
61 ms |
16064 KB |
Output is correct |
3 |
Correct |
326 ms |
16076 KB |
Output is correct |
4 |
Correct |
415 ms |
16076 KB |
Output is correct |
5 |
Correct |
366 ms |
16076 KB |
Output is correct |
6 |
Correct |
359 ms |
16076 KB |
Output is correct |
7 |
Correct |
413 ms |
16096 KB |
Output is correct |
8 |
Correct |
343 ms |
16076 KB |
Output is correct |
9 |
Incorrect |
361 ms |
16076 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |