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>
#define int long long
#define fi first
#define se second
using namespace std;
const int inf = 1e9;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
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() + 1, a.end());
if (p + q >= n) {
cout << 1 << '\n';
return 0;
}
int lf = 0, rg = inf, ans = -1;
while (lf <= rg) {
int md = (lf + rg) / 2;
int ok = 0;
vector<vector<int>> dp(p + 1, vector<int>(q + 1));
for (int i = 0; i <= p; i++) {
for (int j = 0; j <= q; j++) {
if (i - 1 >= 0) {
int x = a[dp[i - 1][j] + 1] + md - 1;
int y = lower_bound(a.begin(), a.end(), x) - a.begin();
dp[i][j] = max(dp[i][j], y);
}
if (j - 1 >= 0) {
int x = a[dp[i][j - 1] + 1] + 2 * md - 1;
int y = lower_bound(a.begin(), a.end(), x) - a.begin();
dp[i][j] = max(dp[i][j], y);
}
if (dp[i][j] == n) {
ok = 1;
goto Next;
}
}
}
Next:;
if (ok) {
ans = md;
rg = md - 1;
} else {
lf = md + 1;
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |