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;
#define int long long
int n, m, inf = 1e15;
priority_queue<pair<pair<int, int>, pair<int, int>>> pq;
int dp[200005];
int c, f, v, a, ran = 0;
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
for(int i = 1; i <= 100000; i++) {
dp[i] = inf;
}
cin >> n;
for(int i = 0; i < n; i++) {
cin >> c >> f >> v;
pq.push({{f, c}, {v, 2}});
}
cin >> m;
for(int i = 0; i < m; i++) {
cin >> c >> f >> v;
pq.push({{f, c}, {v, 1}});
}
while(!pq.empty()) {
c = pq.top().first.second;
v = pq.top().second.first;
a = pq.top().second.second;
pq.pop();
if(a == 2) {
for(int i = 100000; i >= 0; i--) {
dp[i + c] = min(dp[i + c], dp[i] + v);
}
ran += c;
} else {
for(int i = c; i <= 100000; i++) {
dp[i - c] = min(dp[i - c], dp[i] - v);
}
}
}
int mini = 0;
for(int i = 0; i <= 100000; i++) {
mini = min(dp[i], mini);
}
mini *= -1;
cout << mini << "\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... |