#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or substracting them
//only step by step debug when necessay
void solve(){
int n; cin>>n;
vector<tuple<int,int,int>> trans;
for (int i = 0; i < n; ++i) {
int c,f,v; cin>>c>>f>>v;
trans.emplace_back(f,c,-v);
}
cin>>n;
for (int i = 0; i < n; ++i) {
int c,f,v; cin>>c>>f>>v;
trans.emplace_back(f,-c,v);
}
sort(trans.begin(),trans.end(),greater<>());
n = trans.size();
int N = 1e6;
ll dp[N]; fill(dp,dp+N,-1e12);
dp[0] = 0;
for(int i = 0; i<n; i++){
int a,c,v; tie(a,c,v) = trans[i];
if(c>0)
for (int j = N-1; j>=0; j--) {
if(j+c>=0&&j+c<N){
dp[j+c] = max(dp[j+c],dp[j]+(ll)v);
}
}
else
for (int j = 0; j<N; j++) {
if(j+c>=0&&j+c<N){
dp[j+c] = max(dp[j+c],dp[j]+(ll)v);
}
}
}
ll res = 0;
for(int i = 0; i<N; i++){
res = max(res,dp[i]);
}
cout<<res<<'\n';
}
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
int t = 1;
while(t--){
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen("input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |