#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n, p, q, a[N];
int dp[N][N];
void Min(int &a, int b) { a = (a > b ? b : a); }
bool Check(int w) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= min(i, p); ++j) dp[i][j] = i - j;
}
for (int i = 0; i < n; ++i) {
int nxt_p = lower_bound(a, a + n, a[i] + w) - a;
int nxt_q = lower_bound(a, a + n, a[i] + w + w) - a;
for (int np = 0; np <= p; ++np) {
Min(dp[nxt_p][np + 1], dp[i][np]);
Min(dp[nxt_q][np], dp[i][np] + 1);
}
}
return dp[n][p] <= q;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> p >> q;
p = min(p, n), q = min(q, n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int l = 0, r = 1e9, cur = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (Check(mid)) {
cur = mid;
r = mid - 1;
} else l = mid + 1;
}
cout << cur << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
8268 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |