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>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define piii pair<pair<int,int>,pair<int,int>>
#define pip pair<int,pair<int,int>>
int dp[100005];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
vector<piii>v;
for(int i = 1; i <= n; i++){
int c,f,h; cin >> c >> f >> h;
v.pb({{f,1},{c,h}});
}
int m; cin >> m;
for(int i = 1; i <= m; i++){
int c,f,h; cin >> c >> f >> h;
v.pb({{f,-1},{c,h}});
}
for(int i = 1; i <= 100000; i++){
dp[i] = -1e18;
}
sort(v.begin(), v.end(), greater<piii>());
for(int i = 0; i < v.size(); i++){
//cout << "here1 >> " << i << endl;
if(v[i].fi.se == 1){
for(int j = 100000; j >= 1; j--){
if(j - v[i].se.fi < 0 || dp[j - v[i].se.fi] == -1e18)continue;
else{
dp[j] = max(dp[j], dp[j - v[i].se.fi] - v[i].se.se);
}
}
}
else{
for(int j = 1; j <= 100000; j++){
if(j + v[i].se.fi > 100000 || dp[j + v[i].se.fi] == -1e18)continue;
else{
dp[j] = max(dp[j], dp[j + v[i].se.fi] + v[i].se.se);
}
}
}
// for(int i = 1; i <= 10; i++){
// cout << "here >> " << dp[i] << endl;
// }
}
int ans = 0;
for(int i = 1; i <= 100000; i++){
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:31:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < v.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... |