This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n;
vector <vector <int> > vec;
for(int i=0;i<n;i++){
int c,f,v;
cin>>c>>f>>v;
vec.pb({f,1,c,v});
}
cin>>m;
for(int i=0;i<m;i++){
int c,f,v;
cin>>c>>f>>v;
vec.pb({f,0,c,v});
}
sort(all(vec));reverse(all(vec));
vector <int> dp(2e5+5,-1e18);
dp[0]=0;
for(int i=0;i<vec.size();i++){
if(vec[i][1]==1){
for(int j=1e5;j>=0;j--)dp[j+vec[i][2]]=max(dp[j+vec[i][2]],dp[j]-vec[i][3]);
}
else{
for(int j=vec[i][2];j<=1e5;j++)dp[j-vec[i][2]]=max(dp[j-vec[i][2]],dp[j]+vec[i][3]);
}
}
int ans=0;
for(int i=0;i<=1e5;i++)ans=max(ans,dp[i]);
cout<<ans<<"\n";
}
/*
*/
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:28:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
# | 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... |