#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin(), a.end());
auto check = [&](int w) {
vector<vector<int>> dp(n + 1, vector<int> (p + 1, q + 1));
vector<int> to(n + 1), to1(n + 1);
for (int i = 1; i <= n; i++) {
to[i] = lower_bound(a.begin(), a.end(), a[i] - w + 1) - a.begin() - 1;
to1[i] = lower_bound(a.begin(), a.end(), a[i] - 2 * w + 1) - a.begin() - 1;
to[i] = max(0, to[i]);
to1[i] = max(0, to1[i]);
}
dp[0] = vector<int> (p + 1, 0);
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].begin(), dp[n].end()) <= 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
1088 ms |
40556 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
726 ms |
12464 KB |
Output is correct |
4 |
Runtime error |
111 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |