#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Item { int f, c, v; };
const int MAXN = 2000, MAXC = 50;
int n, m;
int dp[2][MAXN * MAXC + 1];
vector<Item> item;
signed
main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for (int i = 0, c, f, v; i < n; i++)
cin >> c >> f >> v, item.push_back({f, c, -v});
cin >> m;
for (int i = 0, c, f, v; i < m; i++)
cin >> c >> f >> v, item.push_back({f, -c, v});
sort(begin(item), end(item), [](Item i, Item j){
return make_tuple(-i.f, i.v, i.c) < make_tuple(-j.f, j.v, j.c);
});
memset(dp, 0xbf, sizeof(dp));
dp[1][0] = dp[0][0] = 0;
for (int i = 0; i < n + m; i++) {
for (int j = 0; j <= MAXN * MAXC; j++)
dp[i&1][j] = dp[(i&1)^1][j];
for (int j = max(0ll, item[i].c);
j <= min(MAXN * MAXC, MAXN * MAXC + item[i].c); j++)
dp[i&1][j] = max(dp[i&1][j], item[i].v + dp[(i&1)^1][j - item[i].c]);
}
int ans = 0;
for (int i = 0; i <= MAXN * MAXC; i++)
ans = max(ans, dp[((n + m)&1)^1][i]);
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
25 ms |
1892 KB |
Output is correct |
4 |
Correct |
47 ms |
1876 KB |
Output is correct |
5 |
Correct |
422 ms |
1968 KB |
Output is correct |
6 |
Correct |
429 ms |
1964 KB |
Output is correct |
7 |
Correct |
456 ms |
1960 KB |
Output is correct |
8 |
Correct |
455 ms |
1960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
4 ms |
1876 KB |
Output is correct |
3 |
Correct |
25 ms |
1892 KB |
Output is correct |
4 |
Correct |
34 ms |
1876 KB |
Output is correct |
5 |
Correct |
209 ms |
1916 KB |
Output is correct |
6 |
Correct |
211 ms |
1912 KB |
Output is correct |
7 |
Correct |
460 ms |
1960 KB |
Output is correct |
8 |
Correct |
441 ms |
1960 KB |
Output is correct |
9 |
Correct |
449 ms |
1964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1888 KB |
Output is correct |
2 |
Correct |
8 ms |
1884 KB |
Output is correct |
3 |
Correct |
41 ms |
1892 KB |
Output is correct |
4 |
Correct |
43 ms |
1876 KB |
Output is correct |
5 |
Correct |
97 ms |
1888 KB |
Output is correct |
6 |
Correct |
102 ms |
1876 KB |
Output is correct |
7 |
Correct |
111 ms |
1876 KB |
Output is correct |
8 |
Correct |
113 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
5 ms |
1876 KB |
Output is correct |
3 |
Correct |
348 ms |
1872 KB |
Output is correct |
4 |
Correct |
402 ms |
1996 KB |
Output is correct |
5 |
Correct |
843 ms |
2124 KB |
Output is correct |
6 |
Correct |
915 ms |
2104 KB |
Output is correct |
7 |
Correct |
887 ms |
2112 KB |
Output is correct |
8 |
Correct |
896 ms |
2108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
38 ms |
1876 KB |
Output is correct |
3 |
Correct |
191 ms |
1924 KB |
Output is correct |
4 |
Correct |
444 ms |
1968 KB |
Output is correct |
5 |
Correct |
892 ms |
2060 KB |
Output is correct |
6 |
Correct |
937 ms |
2056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
25 ms |
1892 KB |
Output is correct |
4 |
Correct |
47 ms |
1876 KB |
Output is correct |
5 |
Correct |
422 ms |
1968 KB |
Output is correct |
6 |
Correct |
429 ms |
1964 KB |
Output is correct |
7 |
Correct |
456 ms |
1960 KB |
Output is correct |
8 |
Correct |
455 ms |
1960 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
4 ms |
1876 KB |
Output is correct |
11 |
Correct |
25 ms |
1892 KB |
Output is correct |
12 |
Correct |
34 ms |
1876 KB |
Output is correct |
13 |
Correct |
209 ms |
1916 KB |
Output is correct |
14 |
Correct |
211 ms |
1912 KB |
Output is correct |
15 |
Correct |
460 ms |
1960 KB |
Output is correct |
16 |
Correct |
441 ms |
1960 KB |
Output is correct |
17 |
Correct |
449 ms |
1964 KB |
Output is correct |
18 |
Correct |
7 ms |
1888 KB |
Output is correct |
19 |
Correct |
8 ms |
1884 KB |
Output is correct |
20 |
Correct |
41 ms |
1892 KB |
Output is correct |
21 |
Correct |
43 ms |
1876 KB |
Output is correct |
22 |
Correct |
97 ms |
1888 KB |
Output is correct |
23 |
Correct |
102 ms |
1876 KB |
Output is correct |
24 |
Correct |
111 ms |
1876 KB |
Output is correct |
25 |
Correct |
113 ms |
1876 KB |
Output is correct |
26 |
Correct |
6 ms |
1876 KB |
Output is correct |
27 |
Correct |
5 ms |
1876 KB |
Output is correct |
28 |
Correct |
348 ms |
1872 KB |
Output is correct |
29 |
Correct |
402 ms |
1996 KB |
Output is correct |
30 |
Correct |
843 ms |
2124 KB |
Output is correct |
31 |
Correct |
915 ms |
2104 KB |
Output is correct |
32 |
Correct |
887 ms |
2112 KB |
Output is correct |
33 |
Correct |
896 ms |
2108 KB |
Output is correct |
34 |
Correct |
2 ms |
1876 KB |
Output is correct |
35 |
Correct |
38 ms |
1876 KB |
Output is correct |
36 |
Correct |
191 ms |
1924 KB |
Output is correct |
37 |
Correct |
444 ms |
1968 KB |
Output is correct |
38 |
Correct |
892 ms |
2060 KB |
Output is correct |
39 |
Correct |
937 ms |
2056 KB |
Output is correct |
40 |
Correct |
266 ms |
1928 KB |
Output is correct |
41 |
Correct |
425 ms |
2004 KB |
Output is correct |
42 |
Correct |
710 ms |
2080 KB |
Output is correct |
43 |
Correct |
907 ms |
2132 KB |
Output is correct |
44 |
Correct |
932 ms |
2132 KB |
Output is correct |
45 |
Correct |
926 ms |
2156 KB |
Output is correct |
46 |
Correct |
492 ms |
2004 KB |
Output is correct |
47 |
Correct |
690 ms |
2084 KB |
Output is correct |
48 |
Correct |
672 ms |
2088 KB |
Output is correct |