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;
int n;
vector <int> events;
vector <vector <int>> dp;
vector <vector <int>> ready;
int solve(int i, int p, int w) {
if (i >= n)
return 0;
if (ready[i][p] == w)
return dp[i][p];
int ans = 1e9;
int it;
if (p >= 1) {
it = upper_bound(events.begin(), events.end(), events[i] + w - 1) - events.begin();
ans = solve(it, p-1, w);
}
it = upper_bound(events.begin(), events.end(), events[i] + 2*w - 1) - events.begin();
ans = min(ans, solve(it, p, w) + 1);
ready[i][p] = w;
dp[i][p] = ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int p, q;
cin >> n >> p >> q;
events = vector <int> (n);
for (int i = 0; i < n; i++)
cin >> events[i];
sort(events.begin(), events.end());
if (p + q >= n) {
cout << 1 << '\n';
return 0;
}
ready = dp = vector <vector <int>> (n+1, vector <int> (p+1));
int lo = 1, hi = 1e9/2;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (solve(0, p, mid) <= q)
hi = mid;
else
lo = mid + 1;
}
cout << lo << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |