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;
ll cnt2 =0;
vector<array<ll,3>>b(m);
for(int i=0;i<m;i++){
cin >> b[i][1] >> b[i][0] >> b[i][2];
cnt2 += b[i][1];
}
sort(a.begin(),a.end(),greater<>());
sort(b.begin(),b.end(),greater<>());
ll idx = 0;
vector<ll>dp(max(cnt,cnt2) + 1);
for(int i=0;i<=max(cnt,cnt2);i++){
dp[i] = -1e18;
}
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= 0;j < dp.size() - b[i][1];j++){
dp[j] = max(dp[j],dp[j+b[i][1]] + b[i][2]);
}
}
cout << *max_element(dp.begin(),dp.end());
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:39:28: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
39 | for(int j= 0;j < dp.size() - b[i][1];j++){
# | 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... |