#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e3 + 2;
int n, a, b, x[maxN], dp[maxN][maxN];
inline bool binF(int searchVal) {
memset(dp, 0x7f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int sw = 1, sw2 = 1;
while (x[i] - x[sw] + 1 > searchVal) sw++;
while (x[i] - x[sw2] + 1 > (searchVal << 1)) sw2++;
for (int j = 0; j <= a; j++) {
dp[i][j] = dp[sw2 - 1][j] + 1;
if (j > 0) dp[i][j] = min(dp[i][j], dp[sw - 1][j - 1]);
}
}
for (int i = 0; i <= a; i++) if (dp[n][i] <= b)
return true;
return false;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> a >> b;
if (a + b >= n) return cout << 1 << '\n', 0;
for (int i = 1; i <= n; i++) cin >> x[i];
sort(x + 1, x + n + 1);
int lo = 1, hi = int(1e9), ans = hi;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (binF(mid)) ans = mid, hi = mid - 1;
else lo = mid + 1;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
15964 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
31 ms |
16140 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
15 ms |
16152 KB |
Output is correct |
8 |
Correct |
12 ms |
15960 KB |
Output is correct |
9 |
Correct |
16 ms |
16148 KB |
Output is correct |
10 |
Correct |
13 ms |
16148 KB |
Output is correct |
11 |
Correct |
15 ms |
15964 KB |
Output is correct |
12 |
Correct |
14 ms |
15964 KB |
Output is correct |
13 |
Correct |
13 ms |
16144 KB |
Output is correct |
14 |
Correct |
19 ms |
16148 KB |
Output is correct |
15 |
Correct |
28 ms |
16216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
15964 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 |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
60 ms |
16132 KB |
Output is correct |
8 |
Correct |
76 ms |
15960 KB |
Output is correct |
9 |
Correct |
108 ms |
16132 KB |
Output is correct |
10 |
Correct |
169 ms |
16212 KB |
Output is correct |
11 |
Correct |
69 ms |
16128 KB |
Output is correct |
12 |
Correct |
120 ms |
15964 KB |
Output is correct |
13 |
Correct |
58 ms |
16124 KB |
Output is correct |
14 |
Correct |
62 ms |
15960 KB |
Output is correct |
15 |
Correct |
68 ms |
15964 KB |
Output is correct |