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
const int MAXS = 1e5;
const int INF = 0x3f3f3f3f3f3f3f3f;
struct O {
int c, f, v;
bool t;
O(int a = 0, int b = 0, int x = 0, bool d = 0) : c(a), f(b), v(x), t(d) {}
bool operator < (const O& a) {
return (make_pair(f, t) < make_pair(a.f, a.t));
}
};
int ant[MAXS + 10], at[MAXS + 10];
int32_t main() {
int n, m;
vector<O> orders;
cin >> n;
for (int i = 0; i < n; i++) {
int c, f, v;
cin >> c >> f >> v;
orders.push_back(O(c, f, v, 1));
}
cin >> m;
for (int i = 0; i < m; i++) {
int c, f, v;
cin >> c >> f >> v;
orders.push_back(O(c, f, v, 0));
}
sort(orders.begin(), orders.end());
//for (int i = 0; i <= MAXS; i++) ant[i] = -INF;
//ant[0] = 0;
int ans = 0;
for (int i = 0; i < (n + m); i++) {
auto u = orders[i];
//cout << u.c << " " << u.f << " " << u.v << " " << u.t << "\n";
for (int j = 0; j <= MAXS; j++) {
at[j] = ant[j];
if (u.t) {
// comprar pc
if ((j + u.c) <= MAXS) {
at[j] = max(at[j], ant[j + u.c] - u.v);
}
} else {
if ((j - u.c) >= 0LL) {
at[j] = max(at[j], ant[j - u.c] + u.v);
}
}
//if (at[j] > ans) cout << i << " " << j << "\n";
//ans = max(ans, at[j]);
}
swap(at, ant);
}
cout << ant[0] << "\n";
}
Compilation message (stderr)
clo.cpp: In function 'int32_t main()':
clo.cpp:39:9: warning: unused variable 'ans' [-Wunused-variable]
39 | int ans = 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... |