This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |