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;
using ll = long long;
using ld = long double;
const ll N = 100003, mod = 1e9 + 7, inf = 1e18 + 7;
struct node
{
int core, rate;
ll cost;
}t;
bool cnt(node a, node b){
if(a.rate == b.rate) return a.cost < b.cost;
return a.rate > b.rate;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
vector<node> v;
for(int i = 0; i < n; ++i){
cin >> t.core >> t.rate >> t.cost;
t.cost = -t.cost;
v.push_back(t);
}
cin >> m;
for(int i = 0; i < m; ++i){
cin >> t.core >> t.rate >> t.cost;
t.core = -t.core;
v.push_back(t);
}
sort(v.begin(), v.end(), cnt);
// for(int i = 0; i < v.size(); ++i) cout << v[i].cost << "\n";
vector<ll> last, dp(N, -inf);
dp[0] = 0;
for(auto i : v){
last = dp;
for(int c = 0; c < N; ++c){
if(0 <= c - i.core && c - i.core < N && last[c - i.core] != -inf){
dp[c] = max(dp[c], last[c - i.core] + i.cost);
}
}
}
ll ans = 0;
for(int i = 0; i < N; ++i){
ans = max(ans, dp[i]);
}
cout << ans;
}
# | 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... |