이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct spec_t {
int c, s;
ll v;
};
int main() {
int n, m, i, j, ccnt = 0;
cin >> n;
vector<spec_t> specs;
for (i = 0; i < n; i++) {
specs.push_back({0, 0, 0});
cin >> specs[i].c >> specs[i].s >> specs[i].v;
ccnt += specs[i].c;
specs[i].v = -specs[i].v;
}
cin >> m;
for (i = n; i < m + n; i++) {
specs.push_back({0, 0, 0});
cin >> specs[i].c >> specs[i].s >> specs[i].v;
specs[i].c = -specs[i].c;
}
specs.push_back({0, INT_MAX, 0});
sort(specs.begin(), specs.end(), [](const spec_t& a, const spec_t& b){return a.s == b.s ? a.v < b.v : a.s > b.s;});
int t = n + m + 1;
vector<vector<ll>> dp(t, vector<ll>(ccnt + 1, LLONG_MIN));
dp[0][0] = 0;
for (i = 1; i < t; i++) {
for (j = 0; j <= ccnt; j++) {
dp[i][j] = dp[i - 1][j];
int prev = j - specs[i].c;
if (prev >= 0 and prev <= ccnt and dp[i - 1][prev] != LLONG_MIN) dp[i][j] = max(dp[i][j], dp[i - 1][prev] + specs[i].v);
}
}
cout << *max_element(dp[t - 1].begin(), dp[t - 1].end());
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... |