#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 2e3+10;
const int INF = 1e9+7;
int a[N];
int dp[N][N];
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
if(p+q >= n) {
cout << "1";
return 0;
}
sort(a+1, a+n+1);
int l = 1, r = INF, w = INF;
while(l <= r) {
int mid = (l+r)/2;
int point_p = 1, point_q = 1;
for(int i = 1; i <= n; i++) {
while(a[i]-a[point_p] >= mid) {
point_p++;
}
while(a[i]-a[point_q] >= 2*mid) {
point_q++;
}
for(int j = 0; j <= p; j++) {
dp[i][j] = INF;
if(j) {
dp[i][j] = min(dp[i][j], dp[point_p-1][j-1]);
}
dp[i][j] = min(dp[i][j], dp[point_q-1][j]+1);
}
}
int res = INF;
for(int i = 0; i <= p; i++) {
res = min(res, dp[n][i]);
}
if(res > q) {
l = mid+1;
}
else {
r = mid-1;
w = min(w, mid);
}
}
cout << w;
return 0;
}
/*
3 1 1
2
11
17
13 3 2
33
66
99
10
83
68
19
83
93
53
15
66
75
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8268 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
9 ms |
8380 KB |
Output is correct |
8 |
Correct |
20 ms |
9312 KB |
Output is correct |
9 |
Correct |
102 ms |
14156 KB |
Output is correct |
10 |
Correct |
216 ms |
16044 KB |
Output is correct |
11 |
Correct |
16 ms |
9032 KB |
Output is correct |
12 |
Correct |
126 ms |
15932 KB |
Output is correct |
13 |
Correct |
7 ms |
8396 KB |
Output is correct |
14 |
Correct |
7 ms |
8396 KB |
Output is correct |
15 |
Correct |
10 ms |
8396 KB |
Output is correct |