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 ll long long
#define endl '\n'
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;cin >> n;
vector<array<ll,3>>a(n);
ll cnt = 0;
for(int i=0;i<n;i++){
cin >> a[i][1] >> a[i][0] >> a[i][2];
cnt += a[i][1];
}
int m;cin >> m;
vector<array<ll,3>>b(m);
for(int i=0;i<m;i++){
cin >> b[i][1] >> b[i][0] >> b[i][2];
}
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
int idx = 0;
vector<ll>dp(cnt,-1e10);
dp[0] = 0;
for(int i=0;i<m;i++){
while(idx < n && b[i][0] <= a[idx][0]){
for(int j = dp.size() - 1;j >= a[idx][1];j--){
dp[j] = max(dp[j],dp[j - a[idx][1]] - a[idx][2]);
}
idx++;
}
for(int j= dp.size()-1;j >= b[i][1];j--){
dp[j] = max(dp[j],dp[j-b[i][1]] + b[i][2]);
}
}
cout << *max_element(dp.begin(),dp.end()) - 6000;
}
# | 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... |