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;
typedef long long ll;
/*
ll tryAll(int i, vector<array<int, 3>>& comps, vector<int> cores, ll cost) {
if (i == comps.size()) {
return solveFor(cur, cost);
}
ll best = tryAll(i + 1, comps, cores, cost);
for (int j = 0; j < comps[i][0]; i++) cores.push(comps[1]);
cost += comps[i][2];
best = max(best, cost);
return best;
}
ll solveFor(vector<int> cores, ll cost) {
ll sum = 0;
return sum - cost;
}
*/
bool comp(const array<int, 4>& ar1, const array<int, 4>& ar2) {
return (ar1[1] > ar2[1]);
}
const int N = 102000;
const ll MIN = -2000000000000000000LL;
ll resAt[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<array<int, 4>> all;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
all.push_back({c, f, v, 0});
}
for (int i = 0; i < N; i++) resAt[i] = MIN;
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
all.push_back({c, f, v, 1});
}
resAt[0] = 0;
sort(all.begin(), all.end(), comp);
for (int i = 0; i < all.size(); i++) {
if (all[i][3] == 0) {
for (int j = N - 1 - all[i][0]; j >= 0; j--) {
resAt[j + all[i][0]] = max(resAt[j + all[i][0]], resAt[j] - all[i][2]);
}
} else {
for (int j = all[i][0]; j <N; j++) {
resAt[j - all[i][0]] = max(resAt[j - all[i][0]], resAt[j] + all[i][2]);
}
}
}
ll res = MIN;
for (int i = 0; i < N; i++ ) {
if (resAt[i] > res) {
res = resAt[i];
}
}
cout << res << "\n";
}
/*
4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550
*/
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 4> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 0; i < all.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |