이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pb push_back
const ll inf = 1e16;
int main() {
int n, m, w;
ll a, c, d;
ll ans = 0;
cin >> n;
vector<ll> dp(n*50+100, -inf);
vector<array<ll, 4>> q;
dp[0] = 0;
w = n*50+1;
for (int i = 0; i < n; ++i) {
cin >> c >> a >> d;
q.pb({a, 1ll, c, -d});
}
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> c >> a >> d;
q.pb({a, 0ll, c, d});
}
sort(q.rbegin(), q.rend());
for (auto u : q) {
if (u[1]) {
for (int i = w-1; i >= u[2]; --i)
dp[i] = max(dp[i], dp[i-u[2]] + u[3]);
} else {
for (int i = 0; i < w; ++i)
dp[i] = max(dp[i], dp[i+u[2]] + u[3]);
}
}
for (auto x : dp)
ans = max(ans, x);
cout << ans << endl;
}
# | 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... |