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;
void Min(int &a, int b) { a = (a > b ? b : a); }
const int N = 2020;
int n, p, q, a[N];
int dp[N][N];
bool Check(long long w) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= p; ++j) dp[i][j] = 1e9;
}
dp[0][0] = 0;
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);
}
}
for (int i = 0; i <= p; ++i) if (dp[n][i] <= q) return true;
return false;
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |