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>
#define ll long long
using namespace std;
struct Transaction {
int c, f, v;
bool operator <(const Transaction& other) { return f > other.f; }
};
ll dp[2][100001];
int main() {
vector<Transaction> trans;
int n; cin >> n;
for(int i = 0; i < n; i++) {
trans.push_back(Transaction());
int c, f, v;
cin >> c >> f >> v;
trans[i].c = c;
trans[i].f = f;
trans[i].v = -v;
}
int m; cin >> m;
for(int i = 0; i < m; i++) {
trans.push_back(Transaction());
int C, F, V;
cin >> C >> F >> V;
trans[n+i].c = -C;
trans[n+i].f = F;
trans[n+i].v = V;
}
sort(trans.begin(), trans.end());
for(int j = 0; j <= 100000; j++) {
dp[0][j] = INT_MIN;
}
dp[0][0] = 0;
if(trans[0].c) dp[0][trans[0].c] = trans[0].v;
for(int t = 1; t < n+m; t++) {
Transaction tn = trans[t];
copy(begin(dp[0]), end(dp[0]), begin(dp[1]));
for(int c = 100000; c >= max(tn.c, 0); c--) {
if(c-tn.c <= 100000)
if(dp[0][c-tn.c] != INT_MIN)
dp[1][c] = max(dp[1][c], dp[0][c-tn.c] + tn.v);
// if(dp[1][c] != INT_MIN) {
// cout << "t: " << t << " c : " << c << endl;
// cout << "c-tnc: " << dp[1][c-tn.c] << " v: " << tn.v << endl;
// cout << "dp: " << dp[1][c] << endl;
// }
}
swap(dp[0], dp[1]);
}
ll res = 0;
for(ll l : dp[0]) res = max(res, l);
cout << res << endl;
}
# | 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... |