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;
const int mxN = 1e5+1;
const ll NINF = -1e18;
ll dp[mxN+10];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<array<int, 3>> v;
for(int i = 0; i < n; i++) {
int cores, freq, price;
cin >> cores >> freq >> price;
v.push_back({cores, freq, price});
}
int m;
cin >> m;
for(int i = 0; i < m; i++) {
int cores, freq, price;
cin >> cores >> freq >> price;
cores = -cores;
v.push_back({cores, freq, price});
}
sort(v.begin(), v.end(), [&](array<int, 3> a, array<int, 3> b) {
if(a[1] == b[1]) {
return a[0] > b[0];
}
else return a[1] > b[1];
});
for(int i = 0; i <= mxN; i++) {
dp[i] = NINF;
}
dp[0] = 0;
for(auto it : v) {
int cores = it[0];
if(cores > 0) {
for(int i = mxN; i >= cores; i--) {
if(dp[i-cores] != NINF) {
dp[i] = max(dp[i], dp[i-cores]-it[2]);
}
}
}
else {
for(int i = abs(cores); i <= mxN; i++) {
if(dp[i] != NINF)
dp[i+cores] = max(dp[i+cores], dp[i]+it[2]);
}
}
}
ll ans = 0;
for(int i = 0; i <= mxN; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
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... |