이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q; cin >> n >> p >> q;
if (p + q >= n) {
cout << 1 << endl;
return 0;
}
vector<int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a.begin(), a.end());
auto ok = [&](int w) -> bool {
int ps = 0, pl = 0;
vector<vector<int>> dp(n + 1, vector<int>(p + 1, n + 1));
fill(dp[0].begin(), dp[0].end(), 0);
for (int i = 0; i < n; ++i) {
while (a[ps] <= a[i] - w) ++ps;
while (a[pl] <= a[i] - 2 * w) ++pl;
for (int j = 0; j <= p; ++j) {
if (j > 0) dp[i + 1][j] = min(dp[i + 1][j], dp[ps][j - 1]);
dp[i + 1][j] = min(dp[i + 1][j], dp[pl][j] + 1);
}
}
return dp[n][p] <= q;
};
int ans = 0, adv = 1;
for (int step = 1; step; adv ? step *= 2 : step /= 2) {
if (ok(ans + step)) adv = 0;
else ans += step;
}
cout << ans + 1 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |