이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// Created by 42kangaroo on 05/01/2023.
//
#include "bits/stdc++.h"
using namespace std;
#define int long long
struct Comp {
int c, r, p;
bool order;
};
bool operator<(const Comp& l, const Comp& r) {
return tie(r.r, l.order) < tie(l.r, r.order);
}
signed main() {
int n;
cin >> n;
vector<Comp> cp(n);
int s = 0;
for (auto& c:cp) {
cin>> c.c >> c.r >> c.p;
s += c.c;
c.order = false;
}
int m;
cin >> m;
cp.resize(n + m);
for (int i = n; i < n + m; ++i) {
cin >> cp[i].c >> cp[i].r >> cp[i].p;
cp[i].order = true;
}
std::sort(cp.begin(), cp.end());
vector<int> dp(s + 1, numeric_limits<int>::min());
dp[0] = 0;
for (auto& o: cp) {
if (o.order) {
for (int i = 0; i <= s - o.c; ++i) {
if (dp[i+o.c] != numeric_limits<int>::min()) {
dp[i] = max(dp[i], dp[i + o.c] + o.p);
}
}
} else {
for (int i = s; i >= o.c; --i) {
if (dp[i - o.c] != numeric_limits<int>::min()) {
dp[i] = max(dp[i], dp[i - o.c] - o.p);
}
}
}
}
int ma = numeric_limits<int>::min();
for (int i = 0; i <= s; ++i) {
ma = max(ma, dp[i]);
}
cout << ma << "\n";
}/*
4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550*/
# | 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... |