#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = 1e18 + 100;
const int N = 1e5 + 10;
int main() {
fast;
vector<tuple<int, int, int>> a;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.emplace_back(f, c, v);
}
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int c, f, v;
cin >> c >> f >> v;
a.emplace_back(f, -c, v);
}
sort(all(a));
reverse(all(a));
ll d[N];
d[0] = 0;
for (int i = 1; i < N; ++i)
d[i] = -INF;
for (auto [f, c, v]: a) {
if (c > 0) {
for (int i = N - 1; i >= c; --i)
d[i] = max(d[i], d[i - c] - v);
}
else {
for (int i = -c; i < N; ++i)
d[i + c] = max(d[i + c], d[i] + v);
}
}
ll ans = 0;
for (int i = 0; i < N; ++i)
ans = max(ans, d[i]);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
17 ms |
1244 KB |
Output is correct |
5 |
Correct |
152 ms |
1300 KB |
Output is correct |
6 |
Correct |
147 ms |
1112 KB |
Output is correct |
7 |
Correct |
155 ms |
1112 KB |
Output is correct |
8 |
Correct |
160 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1116 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
9 ms |
1116 KB |
Output is correct |
5 |
Correct |
69 ms |
1116 KB |
Output is correct |
6 |
Correct |
68 ms |
1248 KB |
Output is correct |
7 |
Correct |
149 ms |
1312 KB |
Output is correct |
8 |
Correct |
153 ms |
1356 KB |
Output is correct |
9 |
Correct |
145 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
4 ms |
1232 KB |
Output is correct |
3 |
Correct |
14 ms |
1116 KB |
Output is correct |
4 |
Correct |
14 ms |
1112 KB |
Output is correct |
5 |
Correct |
32 ms |
1492 KB |
Output is correct |
6 |
Correct |
28 ms |
1116 KB |
Output is correct |
7 |
Correct |
38 ms |
1116 KB |
Output is correct |
8 |
Correct |
39 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
2 ms |
1240 KB |
Output is correct |
3 |
Correct |
113 ms |
1264 KB |
Output is correct |
4 |
Correct |
142 ms |
1272 KB |
Output is correct |
5 |
Correct |
289 ms |
1372 KB |
Output is correct |
6 |
Correct |
304 ms |
1624 KB |
Output is correct |
7 |
Correct |
304 ms |
1372 KB |
Output is correct |
8 |
Correct |
299 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
13 ms |
1248 KB |
Output is correct |
3 |
Correct |
67 ms |
1364 KB |
Output is correct |
4 |
Correct |
151 ms |
1112 KB |
Output is correct |
5 |
Correct |
301 ms |
1372 KB |
Output is correct |
6 |
Correct |
307 ms |
1340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
17 ms |
1244 KB |
Output is correct |
5 |
Correct |
152 ms |
1300 KB |
Output is correct |
6 |
Correct |
147 ms |
1112 KB |
Output is correct |
7 |
Correct |
155 ms |
1112 KB |
Output is correct |
8 |
Correct |
160 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
9 ms |
1116 KB |
Output is correct |
13 |
Correct |
69 ms |
1116 KB |
Output is correct |
14 |
Correct |
68 ms |
1248 KB |
Output is correct |
15 |
Correct |
149 ms |
1312 KB |
Output is correct |
16 |
Correct |
153 ms |
1356 KB |
Output is correct |
17 |
Correct |
145 ms |
1116 KB |
Output is correct |
18 |
Correct |
3 ms |
1116 KB |
Output is correct |
19 |
Correct |
4 ms |
1232 KB |
Output is correct |
20 |
Correct |
14 ms |
1116 KB |
Output is correct |
21 |
Correct |
14 ms |
1112 KB |
Output is correct |
22 |
Correct |
32 ms |
1492 KB |
Output is correct |
23 |
Correct |
28 ms |
1116 KB |
Output is correct |
24 |
Correct |
38 ms |
1116 KB |
Output is correct |
25 |
Correct |
39 ms |
1116 KB |
Output is correct |
26 |
Correct |
2 ms |
1116 KB |
Output is correct |
27 |
Correct |
2 ms |
1240 KB |
Output is correct |
28 |
Correct |
113 ms |
1264 KB |
Output is correct |
29 |
Correct |
142 ms |
1272 KB |
Output is correct |
30 |
Correct |
289 ms |
1372 KB |
Output is correct |
31 |
Correct |
304 ms |
1624 KB |
Output is correct |
32 |
Correct |
304 ms |
1372 KB |
Output is correct |
33 |
Correct |
299 ms |
1372 KB |
Output is correct |
34 |
Correct |
1 ms |
1116 KB |
Output is correct |
35 |
Correct |
13 ms |
1248 KB |
Output is correct |
36 |
Correct |
67 ms |
1364 KB |
Output is correct |
37 |
Correct |
151 ms |
1112 KB |
Output is correct |
38 |
Correct |
301 ms |
1372 KB |
Output is correct |
39 |
Correct |
307 ms |
1340 KB |
Output is correct |
40 |
Correct |
86 ms |
1252 KB |
Output is correct |
41 |
Correct |
147 ms |
1112 KB |
Output is correct |
42 |
Correct |
236 ms |
1340 KB |
Output is correct |
43 |
Correct |
305 ms |
1368 KB |
Output is correct |
44 |
Correct |
303 ms |
1372 KB |
Output is correct |
45 |
Correct |
299 ms |
1368 KB |
Output is correct |
46 |
Correct |
152 ms |
1116 KB |
Output is correct |
47 |
Correct |
233 ms |
1340 KB |
Output is correct |
48 |
Correct |
220 ms |
1116 KB |
Output is correct |