#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int a[n + 1], b[m + 1], s[n + 1], t[m + 1], p[n + 1], q[m + 1];
int x[n + 1], y[m + 1];
for(int i = 1; i <= n; i++) cin >> a[i] >> s[i] >> p[i];
for(int i = 1; i <= m; i++) cin >> b[i] >> t[i] >> q[i];
x[0] = 0;
y[0] = 0;
for(int i = 1; i <= n; i++) x[i] = x[i - 1] + a[i];
for(int i = 1; i <= m; i++) y[i] = y[i - 1] + b[i];
int dp[n + 1][m + 1];
dp[0][0] = 0;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
if(i == 0 && j == 0) continue;
dp[i][j] = -1e18;
if(i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j] + (x[i] + y[j] <= s[i]) * p[i]);
if(j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1] + (x[i] + y[j] <= t[j]) * q[j]);
}
}
cout << dp[n][m];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
784 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
35 ms |
31848 KB |
Output is correct |
18 |
Correct |
31 ms |
31840 KB |
Output is correct |
19 |
Correct |
32 ms |
31844 KB |
Output is correct |
20 |
Correct |
29 ms |
29540 KB |
Output is correct |
21 |
Correct |
31 ms |
30556 KB |
Output is correct |
22 |
Correct |
36 ms |
31840 KB |
Output is correct |
23 |
Correct |
34 ms |
31852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
35 ms |
31848 KB |
Output is correct |
18 |
Correct |
31 ms |
31840 KB |
Output is correct |
19 |
Correct |
32 ms |
31844 KB |
Output is correct |
20 |
Correct |
29 ms |
29540 KB |
Output is correct |
21 |
Correct |
31 ms |
30556 KB |
Output is correct |
22 |
Correct |
36 ms |
31840 KB |
Output is correct |
23 |
Correct |
34 ms |
31852 KB |
Output is correct |
24 |
Runtime error |
653 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
35 ms |
31848 KB |
Output is correct |
18 |
Correct |
31 ms |
31840 KB |
Output is correct |
19 |
Correct |
32 ms |
31844 KB |
Output is correct |
20 |
Correct |
29 ms |
29540 KB |
Output is correct |
21 |
Correct |
31 ms |
30556 KB |
Output is correct |
22 |
Correct |
36 ms |
31840 KB |
Output is correct |
23 |
Correct |
34 ms |
31852 KB |
Output is correct |
24 |
Runtime error |
653 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
0 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
352 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
35 ms |
31848 KB |
Output is correct |
18 |
Correct |
31 ms |
31840 KB |
Output is correct |
19 |
Correct |
32 ms |
31844 KB |
Output is correct |
20 |
Correct |
29 ms |
29540 KB |
Output is correct |
21 |
Correct |
31 ms |
30556 KB |
Output is correct |
22 |
Correct |
36 ms |
31840 KB |
Output is correct |
23 |
Correct |
34 ms |
31852 KB |
Output is correct |
24 |
Runtime error |
653 ms |
1048576 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
784 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
784 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |