이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
void testCase() {
int n, p, q;
cin >> n >> p >> q;
p = min(p, n + 50);
q = min(q, n + 50);
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin(), a.end());
auto check = [&](int w) {
vector<vector<int>> dp(n + 1, vector<int> (p + 1, q + 1));
vector<int> to(n + 1), to1(n + 1);
for (int i = 1; i <= n; i++) {
to[i] = lower_bound(a.begin(), a.end(), a[i] - w + 1) - a.begin() - 1;
to1[i] = lower_bound(a.begin(), a.end(), a[i] - 2 * w + 1) - a.begin() - 1;
to[i] = max(0, to[i]);
to1[i] = max(0, to1[i]);
}
dp[0] = vector<int> (p + 1, 0);
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
if (j) dp[i][j] = dp[to[i]][j - 1];
if (dp[to1[i]][j] < q) dp[i][j] = min(dp[i][j], dp[to1[i]][j] + 1);
}
}
return (*min_element(dp[n].begin(), dp[n].end()) <= q);
};
int lo = 1, hi = 1e9;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (check(mid)) hi = mid;
else lo = mid + 1;
}
cout << lo << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |