이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
struct t {
int c, f, v;
bool operator<(const t &other) {
return f == other.f ? v < other.v : f > other.f;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int s = 0;
vector<t> Events;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
v *= -1;
Events.push_back({c, f, v});
s += c;
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
c *= -1;
Events.push_back({c, f, v});
}
sort(Events.begin(), Events.end());
vector<int64_t> dp(s + 1, -1e18);
dp[0] = 0;
for (auto &x : Events) {
auto ndp = dp;
for (int j = 0; j <= s; j++) {
int pv = j - x.c;
if (0 <= pv && pv <= s) {
ndp[j] = max(ndp[j], dp[pv] + x.v);
}
}
swap(dp, ndp);
}
cout << *max_element(dp.begin(), dp.end());
}
# | 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... |