이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Item { int f, c, v; };
const int MAXN = 2000, MAXC = 50;
int n, m;
int dp[2][MAXN * MAXC + 1];
vector<Item> item;
signed
main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 0, c, f, v; i < n; i++)
cin >> c >> f >> v, item.push_back({f, c, -v});
cin >> m;
for (int i = 0, c, f, v; i < m; i++)
cin >> c >> f >> v, item.push_back({f, -c, v});
sort(begin(item), end(item), [](Item i, Item j){
return make_tuple(-i.f, i.v, i.c) < make_tuple(-j.f, j.v, j.c);
});
memset(dp, 0xbf, sizeof(dp));
dp[1][0] = dp[0][0] = 0;
for (int i = 0; i < n + m; i++) {
for (int j = 0; j <= MAXN * MAXC; j++)
dp[i&1][j] = dp[(i&1)^1][j];
for (int j = max(0ll, item[i].c);
j <= min(MAXN * MAXC, MAXN * MAXC + item[i].c); j++)
dp[i&1][j] = max(dp[i&1][j], item[i].v + dp[(i&1)^1][j - item[i].c]);
}
int ans = 0;
for (int i = 0; i <= MAXN * MAXC; i++)
ans = max(ans, dp[((n + m)&1)^1][i]);
cout << ans << "\n";
return 0;
}
# | 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... |