이 제출은 이전 버전의 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<ll> dp1(ccnt + 1, LLONG_MIN);
dp1[0] = 0;
for (i = 1; i < t; i++) {
vector<ll> dp2 = dp1;
for (j = 0; j <= ccnt; j++) {
int prev = j - specs[i].c;
if (prev >= 0 and prev <= ccnt and dp1[prev] != LLONG_MIN) dp2[j] = max(dp2[j], dp1[prev] + specs[i].v);
}
swap(dp1, dp2);
}
cout << *max_element(dp1.begin(), dp1.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... |