#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int64_t oo = 1e15;
#define int long long
#define quickly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I)
#define FOA(I, A) for(auto I : A)
#define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n';
#define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n';
#define printz(A,L,R) FOR(OK, 0, L){FOR(KO, 0, R){if(A[OK][KO]>-oo&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n';
#define fs first
#define sd second
#define th second.second
#define ii pair<int,int>
#define iii pair<int, ii>
#define all(A) A.begin(), A.end()
const int N = 4000 + 5;
const int mod = 1e9 + 7;
struct item{
int wei, cap, val, in;
};
int n, m, s1, s2, lim;
item a[N];
int dp[25 * N];
signed main(){ quickly
freopen("CLOUD.INP", "r", stdin);
freopen("CLOUD.OUT", "w", stdout);
cin >> n;
FOR(i, 1, n){
cin >> a[i].wei >> a[i].cap >> a[i].val;
a[i].in = i;
s1 += a[i].wei;
}
cin >> m;
FOR(i, n + 1, m + n){
cin >> a[i].wei >> a[i].cap >> a[i].val;
a[i].in = i;
s2 += a[i].wei;
}
lim = max(s1, s2);
sort(a + 1, a + 1 + n + m, [&](item &u, item &v){
if(u.cap == v.cap){
return u.in < v.in;
}
return u.cap > v.cap;
});
memset(dp, -0x3f, sizeof dp);
dp[0] = 0;
FOR(i, 1, n + m){
int w = a[i].wei, v = a[i].val;
if(a[i].in <= n){
FOD(s, lim, w){
dp[s] = max(dp[s], dp[s - w] - v);
}
}
else{
FOR(s, 0, lim - w){
dp[s] = max(dp[s], dp[s + w] + v);
}
}
}
cout << *max_element(dp, dp + 1 + lim);
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen("CLOUD.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen("CLOUD.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... |