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>
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';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |