이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n, p, q, a[N];
int dp[N][N];
void Max(int &a, int b) { a = (a < b ? b : a); }
bool Check(int w) {
memset(dp, 0, sizeof dp);
int total = min(n, p + q);
for (int i = 0; i < total; ++i) {
for (int np = 0; np <= min(i, p); ++np) {
int x = dp[i][np];
int nq = i - np;
if (x == n) {
return true;
}
if (np < p) {
int nxt = lower_bound(a, a + n, a[x] + w) - a;
Max(dp[i + 1][np + 1], nxt);
}
if (nq < q) {
int nxt = lower_bound(a, a + n, a[x] + w + w) - a;
Max(dp[i + 1][np], nxt);
}
}
}
return dp[total][p] >= n;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> p >> q;
p = min(p, n), q = min(q, n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int l = 0, r = 1e9, cur = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (Check(mid)) {
cur = mid;
r = mid - 1;
} else l = mid + 1;
}
cout << cur << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |