#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
//--------------------------------------------------------------------
ll n, m;
const ll N = 4003;
struct state {
ll c, f, v, id;
bool operator < (const state &a) const {
return f > a.f || f == a.f && id < a.id;
}
};
state a[N];
ll c[N];
ll dp[100003];
void hbmt() {
cin >> n;
FOR(i, 1, n) {
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].id = 1;
}
cin >> m;
FOR(i, n + 1, m + n) {
cin >> a[i].c >> a[i].f >> a[i].v;
a[i].id = 2;
}
sort(a + 1, a + n + m + 1);
memset(dp, -0x3f, sizeof dp);
dp[0] = 0;
FOR(i, 1, n + m) {
if(a[i].id == 1) {
FORD(j, 1e5, a[i].c) {
if(dp[j - a[i].c] > -INF)
dp[j] = max(dp[j], dp[j - a[i].c] - a[i].v);
}
}
else {
FOR(j, 0, (ll)1e5 - a[i].c) {
if(dp[j + a[i].c] > -INF)
dp[j] = max(dp[j], dp[j + a[i].c] + a[i].v);
}
}
}
cout << *max_element(dp, dp + (ll)1e5 + 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#define NAME "hbmt"
if(fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
//int t;cin>>t;while(t--)
hbmt();
return 0;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |