#include<bits/stdc++.h>
using namespace std;
const int N = 2000;
const int A = 1e9;
const int INF = 1e9;
int n, p, q;
int a[N + 5];
int nextP[N + 5], nextQ[N + 5];
int memo[N + 5][N + 5];
int dp(int idx, int p) {
if (p < 0) return INF;
if (idx >= n) return 0;
int &ret = memo[idx][p];
if (memo[idx][p] != -1) return ret;
ret = min(dp(nextP[idx], p - 1), dp(nextQ[idx], p) + 1);
return ret;
}
bool solve(int w) {
int j = 1, k = 1;
for(int i = 0; i < n; i++){
while(j < n && a[j] - a[i] + 1 <= w) j++;
while(k < n && a[k] - a[i] + 1 <= 2*w) k++;
nextP[i] = j;
nextQ[i] = k;
}
memset(memo, -1, sizeof(memo));
return dp(0, p) <= q;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (p + q >= n) {
cout << 1 << "\n";
return 0;
}
sort(a, a + n);
int l = 1, r = A, ans = INF;
while (l <= r) {
int mid = (l + r) / 2;
if (solve(mid)) {
ans = min(ans, mid);
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
15960 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
24 ms |
15960 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
24 ms |
16204 KB |
Output is correct |
8 |
Correct |
24 ms |
15964 KB |
Output is correct |
9 |
Correct |
25 ms |
15964 KB |
Output is correct |
10 |
Correct |
27 ms |
15964 KB |
Output is correct |
11 |
Correct |
24 ms |
15960 KB |
Output is correct |
12 |
Correct |
25 ms |
15964 KB |
Output is correct |
13 |
Correct |
23 ms |
15960 KB |
Output is correct |
14 |
Correct |
24 ms |
15968 KB |
Output is correct |
15 |
Correct |
22 ms |
16216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
16216 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
24 ms |
16232 KB |
Output is correct |
8 |
Correct |
40 ms |
16220 KB |
Output is correct |
9 |
Correct |
80 ms |
16220 KB |
Output is correct |
10 |
Correct |
220 ms |
16544 KB |
Output is correct |
11 |
Correct |
45 ms |
16220 KB |
Output is correct |
12 |
Correct |
148 ms |
16304 KB |
Output is correct |
13 |
Correct |
23 ms |
16220 KB |
Output is correct |
14 |
Correct |
25 ms |
16216 KB |
Output is correct |
15 |
Correct |
22 ms |
16472 KB |
Output is correct |