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;
struct action{
int core, clock, price;
};
bool cmp(action a, action b){
return a.clock != b.clock ? a.clock > b.clock : a.price < b.price;
}
int main()
{
int n,m; cin >> n;
int num = 0;
vector<action> inputs;
for(int i = 0;i<n;++i){
int a,b,c; cin >> a >> b >> c;
inputs.push_back({a,b,-c});
num += a;
}
cin >> m;
for(int i = 0;i<m;++i){
int a,b,c; cin >> a >> b >> c;
inputs.push_back({-a,b,c});
}
sort(inputs.begin(),inputs.end(),cmp);
vector<long long> answers(num+1, INT64_MIN);
answers[0] = 0;
for (const action &ac : inputs) {
vector<long long> newm(answers);
for(int cur = 0; cur<=num;++cur){
int prev = cur-ac.core;
if (0 <= prev && prev <= num && answers[prev] != INT64_MIN) {
newm[cur] = max(newm[cur], answers[prev]+ac.price);
}
}
answers = newm;
}
cout << *max_element(answers.begin(), answers.end()) << "\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... |