#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops,Ofast")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt,tune=native")
#define all(x) x.begin(), x.end()
vector<vector<int>> v;
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
int n, m, cores = 0; cin >> n;
for(int i = 0, a, b, c; i < n; ++i){
cin >> a >> b >> c;
v.push_back({b, 1, a, c});
cores += a;
}
cin >> m;
for(int i = 0, a, b, c; i < m; ++i){
cin >> a >> b >> c;
v.push_back({b, 0, a, c});
cores += a;
}
sort(all(v), greater<>());
vector<long long> dp(cores + 2, 0);
for(int i = v.size() - 1; i >= 0; --i){
if(v[i][1] == 1){
for(int j = 0; j <= cores; ++j){
if(j + v[i][2] <= cores) dp[j] = max(dp[j], (long long) dp[j + v[i][2]] - v[i][3]);
}
}else{
for(int j = cores; j >= 0; --j){
if(v[i][2] <= j) dp[j] = max(dp[j], (long long) dp[j - v[i][2]] + v[i][3]);
}
}
}
cout << dp[0] << "\n";
return 0;
}
| # | 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... |