#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 3000;
int dp[mxN][mxN];
int a[mxN];
int to[mxN], to1[mxN];
void testCase() {
int n, p, q;
cin >> n >> p >> q;
p = min(p, n + 50);
q = min(q, n + 50);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a, a + n + 1);
auto check = [&](int w) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= p; j++) {
dp[i][j] = q + 1;
if (i == 0) dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
to[i] = lower_bound(a, a + n + 1, a[i] - w + 1) - a - 1;
to1[i] = lower_bound(a, a + n + 1, a[i] - 2 * w + 1) - a - 1;
to[i] = max(0, to[i]);
to1[i] = max(0, to1[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
if (j) dp[i][j] = dp[to[i]][j - 1];
if (dp[to1[i]][j] < q) dp[i][j] = min(dp[i][j], dp[to1[i]][j] + 1);
}
}
return (*min_element(dp[n], dp[n] + p + 1) <= q);
};
int lo = 1, hi = 1e9;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (check(mid)) hi = mid;
else lo = mid + 1;
}
cout << lo << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
1 ms |
724 KB |
Output is correct |
13 |
Correct |
1 ms |
724 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8416 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
271 ms |
20172 KB |
Output is correct |
4 |
Correct |
422 ms |
23764 KB |
Output is correct |
5 |
Correct |
27 ms |
8956 KB |
Output is correct |
6 |
Correct |
379 ms |
23852 KB |
Output is correct |
7 |
Correct |
14 ms |
8404 KB |
Output is correct |
8 |
Correct |
35 ms |
9328 KB |
Output is correct |
9 |
Correct |
149 ms |
14268 KB |
Output is correct |
10 |
Correct |
325 ms |
23228 KB |
Output is correct |
11 |
Correct |
25 ms |
9044 KB |
Output is correct |
12 |
Correct |
190 ms |
16012 KB |
Output is correct |
13 |
Correct |
13 ms |
8472 KB |
Output is correct |
14 |
Correct |
15 ms |
8532 KB |
Output is correct |
15 |
Correct |
17 ms |
8532 KB |
Output is correct |