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 Object{
int c, f, v;
bool operator< (const Object& o) const{
return (f == o.f && v < o.v) || (f > o.f);
}
};
int main(){
int n;
cin >> n;
vector<Object> objects;
for(int i = 0; i < n; i++){
int c, f, v;
cin >> c >> f >> v;
objects.push_back({c, f, -v});
}
int m;
cin >> m;
for(int i = 0; i < m; i++){
int c, f, v;
cin >> c >> f >> v;
objects.push_back({-c, f, v});
}
sort(objects.begin(), objects.end());
vector<long long> dp(100001, -1e14);
dp[0] = 0;
for(int i = 0; i < n + m; i++){
vector<long long> ndp(100001, -1e14);
ndp[0] = 0;
for(int c = 0; c <= 100000; c++){
if(c - objects[i].c <= 100000 && objects[i].c <= c){
ndp[c] = max(ndp[c], dp[c - objects[i].c] + objects[i].v);
}
}
for(int c = 0; c <= 100000; c++){
dp[c] = max(dp[c], ndp[c]);
}
}
long long maxVal = -1e14;
for(int i = 0; i <= 100000; i++){
maxVal = max(maxVal, dp[i]);
}
cout << maxVal << "\n";
}
# | 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... |