This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MX 100001
vector<tuple<int, int, int>> v;
int dp[MX];
signed main() {
memset(dp,-8,sizeof dp);
dp[0]=0;
int n, m;
cin >> n;
while(n--) {
int a, b, c;
cin >> a >> b >> c;
v.push_back({b,a,-c});
}
cin >> m;
while(m--) {
int a, b, c;
cin >> a >> b >> c;
v.push_back({b,-a,c});
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
for(auto K: v) {
int a, b, c;
tie(a,b,c)=K;
if(b > 0) {
for(int i = MX; i-- > b;)
dp[i]=max(dp[i],c+dp[i-b]);
} else {
for(int i = 0; i < MX+b; i++)
dp[i]=max(dp[i],c+dp[i-b]);
}
}
cout << *max_element(dp,dp+MX);
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... |