이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int find_maximum_unique(int x, int y, vector<int> a, vector<int> b) {
int n = (int) a.size();
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) { return a[i] - b[i] < a[j] - b[j]; });
const int inf = (int) 1e9;
vector<vector<int>> dp1(n + 1, vector<int>(n + 1, inf));
dp1[0][0] = 0;
for (int i = 0; i < n; i++) {
dp1[i + 1] = dp1[i];
for (int j = i; j >= 0; j--) {
dp1[i + 1][j + 1] = min(dp1[i + 1][j + 1], dp1[i][j] + a[order[i]]);
}
}
vector<vector<int>> dp2(n + 1, vector<int>(n + 1, inf));
dp2[0][0] = 0;
for (int i = 0; i < n; i++) {
dp2[i + 1] = dp2[i];
for (int j = i; j >= 0; j--) {
dp2[i + 1][j + 1] = min(dp2[i + 1][j + 1], dp2[i][j] + b[order[n - 1 - i]]);
}
}
vector<int> c1(n + 1);
for (int i = 0; i <= n; i++) {
for (int j = i; j >= 0; j--) {
if (dp1[i][j] <= x) {
c1[i] = j;
break;
}
}
}
vector<int> c2(n + 1);
for (int i = 0; i <= n; i++) {
for (int j = i; j >= 0; j--) {
if (dp2[i][j] <= y) {
c2[i] = j;
break;
}
}
}
int ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, c1[i] + c2[n - i]);
}
return ans;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << find_maximum_unique(2, 3, {2, 1, 4}, {2, 3, 2}) << '\n';
cout << find_maximum_unique(6, 12, {5, 1, 5, 6, 3}, {3, 5, 4, 6, 7}) << '\n';
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |