#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
#define all(x) x.begin(), x.end()
#define ckmin(a,b) a = min(a,b)
#define ckmax(a,b) a = max(a,b)
struct Computer {
int c;
ll f;
ll v;
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int N;
cin >> N;
vector<Computer> store(N);
for (int i=0;i<N;i++) cin >> store[i].c >> store[i].f >> store[i].v;
int M;
cin >> M;
vector<Computer> orders(M);
for (int i=0;i<M;i++) cin >> orders[i].c >> orders[i].f >> orders[i].v;
using Event = tuple<ll, int, ll>;
vector<Event> events;
for (int i=0;i<N;i++) {
events.push_back({store[i].f, store[i].c, -store[i].v});
}
for (int i=0;i<M;i++) {
events.push_back({orders[i].f, -orders[i].c, orders[i].v});
}
sort(all(events));
reverse(all(events));
int E = (int)events.size();
int maxC = 50*N;
// vvll dp(E+1, vll(maxC + 1, -1e18));
vll dp(maxC + 1, -1e18);
dp[0] = 0;
// dp[0][0] = 0;
for (int i=0;i<E;i++) {
auto [f, c, v] = events[i];
if (c > 0) {
// store
// for (int cp=0;cp+c<=maxC;cp++) {
// ckmax(dp[i+1][cp+c], dp[i][cp] + v);
// }
for (int cp=maxC-c;cp>=0;cp--) {
ckmax(dp[cp+c], dp[cp] + v);
}
} else {
// order
// for (int cp=-c;cp<=maxC;cp++) {
// ckmax(dp[i+1][cp+c], dp[i][cp] + v);
// }
for (int cp=-c;cp<=maxC;cp++) {
ckmax(dp[cp+c], dp[cp] + v);
}
}
// can also ignore i
// for (int cp=0;cp<=maxC;cp++) ckmax(dp[i+1][cp], dp[i][cp]);
}
ll ans = 0;
// for (int c=0;c<=maxC;c++) ckmax(ans, dp[E][c]);
for (int c=0;c<=maxC;c++) ckmax(ans, dp[c]);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
28 ms |
880 KB |
Output is correct |
6 |
Correct |
28 ms |
860 KB |
Output is correct |
7 |
Correct |
136 ms |
1368 KB |
Output is correct |
8 |
Correct |
133 ms |
1420 KB |
Output is correct |
9 |
Correct |
127 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
75 ms |
1116 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
238 ms |
1552 KB |
Output is correct |
6 |
Correct |
256 ms |
1616 KB |
Output is correct |
7 |
Correct |
252 ms |
1372 KB |
Output is correct |
8 |
Correct |
268 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
15 ms |
604 KB |
Output is correct |
4 |
Correct |
51 ms |
860 KB |
Output is correct |
5 |
Correct |
255 ms |
1368 KB |
Output is correct |
6 |
Correct |
259 ms |
1616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
28 ms |
880 KB |
Output is correct |
14 |
Correct |
28 ms |
860 KB |
Output is correct |
15 |
Correct |
136 ms |
1368 KB |
Output is correct |
16 |
Correct |
133 ms |
1420 KB |
Output is correct |
17 |
Correct |
127 ms |
1372 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
348 KB |
Output is correct |
24 |
Correct |
5 ms |
344 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
75 ms |
1116 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
238 ms |
1552 KB |
Output is correct |
31 |
Correct |
256 ms |
1616 KB |
Output is correct |
32 |
Correct |
252 ms |
1372 KB |
Output is correct |
33 |
Correct |
268 ms |
1536 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
15 ms |
604 KB |
Output is correct |
37 |
Correct |
51 ms |
860 KB |
Output is correct |
38 |
Correct |
255 ms |
1368 KB |
Output is correct |
39 |
Correct |
259 ms |
1616 KB |
Output is correct |
40 |
Correct |
17 ms |
600 KB |
Output is correct |
41 |
Correct |
46 ms |
860 KB |
Output is correct |
42 |
Correct |
147 ms |
1328 KB |
Output is correct |
43 |
Correct |
256 ms |
1372 KB |
Output is correct |
44 |
Correct |
287 ms |
1372 KB |
Output is correct |
45 |
Correct |
264 ms |
1624 KB |
Output is correct |
46 |
Correct |
67 ms |
860 KB |
Output is correct |
47 |
Correct |
141 ms |
1112 KB |
Output is correct |
48 |
Correct |
139 ms |
1116 KB |
Output is correct |