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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"
const int MOD = 1e9+7;
const int inf = 1e9;
const int linf = 1e18;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// -------------------------------------------------- Main Code --------------------------------------------------
int dp[2005][2005];
int n, nxtP[2005], nxtQ[2005], arr[2005];
int sol(int idx, int p) {
if (idx >= n) return 0;
if (dp[idx][p] != -1) return dp[idx][p];
int ans = inf;
if (p) ans = min(ans, sol(nxtP[idx]+1, p-1));
ans = min(ans, sol(nxtQ[idx]+1, p) + 1);
return dp[idx][p] = ans;
}
void sol() {
int p, q; cin >> n >> p >> q;
p = min(p, n); q = min(q, n);
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr+n);
auto fiss = [&](int mid) {
for (int i = 0; i <= n; i++) for (int j = 0; j <= p; j++) dp[i][j] = -1;
for (int i = 0; i < n; i++) {
nxtP[i] = upper_bound(arr, arr+n, arr[i]+mid-1) - arr - 1;
nxtQ[i] = upper_bound(arr, arr+n, arr[i]+2*mid-1) - arr - 1;
}
return (sol(0, p) <= q);
};
int i = 0, j = inf, ans = inf;
while (i <= j) {
int mid = (i+j)/2;
if (fiss(mid)) ans = mid, j = mid-1;
else i = mid+1;
}
cout << ans << endl;
}
signed main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
sol();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |