#include <bits/stdc++.h>
#define int long long
using namespace std;
const int M = 1 << 18, N = 2 * M, INF = 1e18 + 42;
int n, m, maxi[N], tag[N], sum[N];
vector<int> a[2], s[2], p[2], pos[2];
void add(int i, int pt) {
i = max(i, 0ll);
i += M;
while(i) {
sum[i] += pt;
i >>= 1;
}
}
int getSum(int i) {
if(i == -1) return 0;
i += M;
int ans = sum[i];
while(i) {
if(i & 1) ans += sum[i-1];
i >>= 1;
}
return ans;
}
void applyOp(int i, int add) {
tag[i] += add;
maxi[i] += add;
}
void propage(int i) {
applyOp(i*2, tag[i]);
applyOp(i*2+1, tag[i]);
tag[i] = 0;
}
int update(int i, int deb, int fin, int l, int r, int add) {
if(r <= deb || fin <= l)
return 0;
if(l <= deb && fin <= r) {
applyOp(i, add);
return maxi[i];
}
propage(i);
int mid = ((deb + fin) >> 1);
int ans = max(update(i*2, deb, mid, l, r, add),
update(i*2+1, mid, fin, l, r, add));
maxi[i] = max(maxi[i*2], maxi[i*2+1]);
return ans;
}
int solve() {
for(int i = 0; i < N; i++)
maxi[i] = tag[i] = sum[i] = 0;
vector<int> ver[M];
for(int i = 1; i <= m; i++)
if(pos[1][i] >= 0)
ver[pos[1][i]].push_back(i);
int ans = 0;
for(int i = n; i >= 0; i--) {
for(int j : ver[i]) {
add(j, p[1][j]);
update(1, 0, M, j, M, p[1][j]);
}
int dp = update(1, 0, M, pos[0][i], M, 0);
ans = max(ans, dp - getSum(pos[0][i]));
int val = update(1, 0, M, pos[0][i], pos[0][i]+1, 0);
update(1, 0, M, pos[0][i], pos[0][i]+1, -val);
update(1, 0, M, pos[0][i], pos[0][i]+1, dp);
update(1, 0, M, 0, pos[0][i]+1, p[0][i]);
}
return ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
int sz[] = {n+1, m+1};
for(int i = 0; i < 2; i++) {
a[i].resize(sz[i]);
s[i].resize(sz[i]);
p[i].resize(sz[i]);
pos[i].resize(sz[i]);
}
for(int i = 1; i <= n; i++)
cin >> a[0][i] >> s[0][i] >> p[0][i];
for(int i = 1; i <= m; i++)
cin >> a[1][i] >> s[1][i] >> p[1][i];
for(int i = 1; i <= n; i++)
a[0][i] += a[0][i-1];
for(int i = 1; i <= m; i++)
a[1][i] += a[1][i-1];
for(int i = 0; i <= n; i++)
pos[0][i] = (int)(upper_bound(a[1].begin(), a[1].end(), s[0][i] - a[0][i]) - a[1].begin())-1;
for(int i = 0; i <= m; i++)
pos[1][i] = (int)(upper_bound(a[0].begin(), a[0].end(), s[1][i] - a[1][i]) - a[0].begin())-1;
int ans = solve();
swap(n, m);
swap(a[0], a[1]);
swap(s[0], s[1]);
swap(p[0], p[1]);
swap(pos[0], pos[1]);
cout << max(ans, solve()) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
537 ms |
37196 KB |
Output is correct |
2 |
Correct |
570 ms |
35528 KB |
Output is correct |
3 |
Correct |
513 ms |
35368 KB |
Output is correct |
4 |
Correct |
406 ms |
35148 KB |
Output is correct |
5 |
Correct |
9 ms |
18772 KB |
Output is correct |
6 |
Correct |
553 ms |
34612 KB |
Output is correct |
7 |
Correct |
274 ms |
27192 KB |
Output is correct |
8 |
Correct |
299 ms |
27220 KB |
Output is correct |
9 |
Correct |
502 ms |
35244 KB |
Output is correct |
10 |
Correct |
573 ms |
38112 KB |
Output is correct |
11 |
Correct |
481 ms |
35460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
18772 KB |
Output is correct |
2 |
Correct |
11 ms |
18768 KB |
Output is correct |
3 |
Correct |
9 ms |
18788 KB |
Output is correct |
4 |
Correct |
9 ms |
18728 KB |
Output is correct |
5 |
Correct |
8 ms |
18684 KB |
Output is correct |
6 |
Correct |
8 ms |
18772 KB |
Output is correct |
7 |
Correct |
10 ms |
18772 KB |
Output is correct |
8 |
Correct |
10 ms |
18724 KB |
Output is correct |
9 |
Correct |
9 ms |
18784 KB |
Output is correct |
10 |
Correct |
10 ms |
18772 KB |
Output is correct |
11 |
Correct |
9 ms |
18772 KB |
Output is correct |
12 |
Correct |
9 ms |
18776 KB |
Output is correct |
13 |
Correct |
9 ms |
18772 KB |
Output is correct |
14 |
Correct |
9 ms |
18704 KB |
Output is correct |
15 |
Correct |
9 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
18780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
18772 KB |
Output is correct |
2 |
Correct |
11 ms |
18768 KB |
Output is correct |
3 |
Correct |
9 ms |
18788 KB |
Output is correct |
4 |
Correct |
9 ms |
18728 KB |
Output is correct |
5 |
Correct |
8 ms |
18684 KB |
Output is correct |
6 |
Correct |
8 ms |
18772 KB |
Output is correct |
7 |
Correct |
10 ms |
18772 KB |
Output is correct |
8 |
Correct |
10 ms |
18724 KB |
Output is correct |
9 |
Correct |
9 ms |
18784 KB |
Output is correct |
10 |
Correct |
10 ms |
18772 KB |
Output is correct |
11 |
Correct |
9 ms |
18772 KB |
Output is correct |
12 |
Correct |
9 ms |
18776 KB |
Output is correct |
13 |
Correct |
9 ms |
18772 KB |
Output is correct |
14 |
Correct |
9 ms |
18704 KB |
Output is correct |
15 |
Correct |
9 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
18780 KB |
Output is correct |
17 |
Correct |
13 ms |
19028 KB |
Output is correct |
18 |
Correct |
13 ms |
19028 KB |
Output is correct |
19 |
Correct |
15 ms |
19028 KB |
Output is correct |
20 |
Correct |
12 ms |
19028 KB |
Output is correct |
21 |
Correct |
16 ms |
19028 KB |
Output is correct |
22 |
Correct |
15 ms |
18900 KB |
Output is correct |
23 |
Correct |
15 ms |
18900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
18772 KB |
Output is correct |
2 |
Correct |
11 ms |
18768 KB |
Output is correct |
3 |
Correct |
9 ms |
18788 KB |
Output is correct |
4 |
Correct |
9 ms |
18728 KB |
Output is correct |
5 |
Correct |
8 ms |
18684 KB |
Output is correct |
6 |
Correct |
8 ms |
18772 KB |
Output is correct |
7 |
Correct |
10 ms |
18772 KB |
Output is correct |
8 |
Correct |
10 ms |
18724 KB |
Output is correct |
9 |
Correct |
9 ms |
18784 KB |
Output is correct |
10 |
Correct |
10 ms |
18772 KB |
Output is correct |
11 |
Correct |
9 ms |
18772 KB |
Output is correct |
12 |
Correct |
9 ms |
18776 KB |
Output is correct |
13 |
Correct |
9 ms |
18772 KB |
Output is correct |
14 |
Correct |
9 ms |
18704 KB |
Output is correct |
15 |
Correct |
9 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
18780 KB |
Output is correct |
17 |
Correct |
13 ms |
19028 KB |
Output is correct |
18 |
Correct |
13 ms |
19028 KB |
Output is correct |
19 |
Correct |
15 ms |
19028 KB |
Output is correct |
20 |
Correct |
12 ms |
19028 KB |
Output is correct |
21 |
Correct |
16 ms |
19028 KB |
Output is correct |
22 |
Correct |
15 ms |
18900 KB |
Output is correct |
23 |
Correct |
15 ms |
18900 KB |
Output is correct |
24 |
Correct |
383 ms |
34780 KB |
Output is correct |
25 |
Correct |
381 ms |
40648 KB |
Output is correct |
26 |
Correct |
450 ms |
44728 KB |
Output is correct |
27 |
Correct |
447 ms |
44804 KB |
Output is correct |
28 |
Correct |
552 ms |
41776 KB |
Output is correct |
29 |
Correct |
506 ms |
42280 KB |
Output is correct |
30 |
Correct |
847 ms |
42688 KB |
Output is correct |
31 |
Correct |
256 ms |
31972 KB |
Output is correct |
32 |
Correct |
289 ms |
32048 KB |
Output is correct |
33 |
Correct |
455 ms |
40996 KB |
Output is correct |
34 |
Correct |
696 ms |
41932 KB |
Output is correct |
35 |
Correct |
763 ms |
39764 KB |
Output is correct |
36 |
Correct |
825 ms |
39868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
18772 KB |
Output is correct |
2 |
Correct |
11 ms |
18768 KB |
Output is correct |
3 |
Correct |
9 ms |
18788 KB |
Output is correct |
4 |
Correct |
9 ms |
18728 KB |
Output is correct |
5 |
Correct |
8 ms |
18684 KB |
Output is correct |
6 |
Correct |
8 ms |
18772 KB |
Output is correct |
7 |
Correct |
10 ms |
18772 KB |
Output is correct |
8 |
Correct |
10 ms |
18724 KB |
Output is correct |
9 |
Correct |
9 ms |
18784 KB |
Output is correct |
10 |
Correct |
10 ms |
18772 KB |
Output is correct |
11 |
Correct |
9 ms |
18772 KB |
Output is correct |
12 |
Correct |
9 ms |
18776 KB |
Output is correct |
13 |
Correct |
9 ms |
18772 KB |
Output is correct |
14 |
Correct |
9 ms |
18704 KB |
Output is correct |
15 |
Correct |
9 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
18780 KB |
Output is correct |
17 |
Correct |
13 ms |
19028 KB |
Output is correct |
18 |
Correct |
13 ms |
19028 KB |
Output is correct |
19 |
Correct |
15 ms |
19028 KB |
Output is correct |
20 |
Correct |
12 ms |
19028 KB |
Output is correct |
21 |
Correct |
16 ms |
19028 KB |
Output is correct |
22 |
Correct |
15 ms |
18900 KB |
Output is correct |
23 |
Correct |
15 ms |
18900 KB |
Output is correct |
24 |
Correct |
383 ms |
34780 KB |
Output is correct |
25 |
Correct |
381 ms |
40648 KB |
Output is correct |
26 |
Correct |
450 ms |
44728 KB |
Output is correct |
27 |
Correct |
447 ms |
44804 KB |
Output is correct |
28 |
Correct |
552 ms |
41776 KB |
Output is correct |
29 |
Correct |
506 ms |
42280 KB |
Output is correct |
30 |
Correct |
847 ms |
42688 KB |
Output is correct |
31 |
Correct |
256 ms |
31972 KB |
Output is correct |
32 |
Correct |
289 ms |
32048 KB |
Output is correct |
33 |
Correct |
455 ms |
40996 KB |
Output is correct |
34 |
Correct |
696 ms |
41932 KB |
Output is correct |
35 |
Correct |
763 ms |
39764 KB |
Output is correct |
36 |
Correct |
825 ms |
39868 KB |
Output is correct |
37 |
Correct |
474 ms |
44648 KB |
Output is correct |
38 |
Correct |
459 ms |
44716 KB |
Output is correct |
39 |
Correct |
582 ms |
44800 KB |
Output is correct |
40 |
Correct |
595 ms |
44924 KB |
Output is correct |
41 |
Correct |
8 ms |
18788 KB |
Output is correct |
42 |
Correct |
781 ms |
42528 KB |
Output is correct |
43 |
Correct |
453 ms |
40748 KB |
Output is correct |
44 |
Correct |
697 ms |
41700 KB |
Output is correct |
45 |
Correct |
803 ms |
36436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
18772 KB |
Output is correct |
2 |
Correct |
11 ms |
18768 KB |
Output is correct |
3 |
Correct |
9 ms |
18788 KB |
Output is correct |
4 |
Correct |
9 ms |
18728 KB |
Output is correct |
5 |
Correct |
8 ms |
18684 KB |
Output is correct |
6 |
Correct |
8 ms |
18772 KB |
Output is correct |
7 |
Correct |
10 ms |
18772 KB |
Output is correct |
8 |
Correct |
10 ms |
18724 KB |
Output is correct |
9 |
Correct |
9 ms |
18784 KB |
Output is correct |
10 |
Correct |
10 ms |
18772 KB |
Output is correct |
11 |
Correct |
9 ms |
18772 KB |
Output is correct |
12 |
Correct |
9 ms |
18776 KB |
Output is correct |
13 |
Correct |
9 ms |
18772 KB |
Output is correct |
14 |
Correct |
9 ms |
18704 KB |
Output is correct |
15 |
Correct |
9 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
18780 KB |
Output is correct |
17 |
Correct |
13 ms |
19028 KB |
Output is correct |
18 |
Correct |
13 ms |
19028 KB |
Output is correct |
19 |
Correct |
15 ms |
19028 KB |
Output is correct |
20 |
Correct |
12 ms |
19028 KB |
Output is correct |
21 |
Correct |
16 ms |
19028 KB |
Output is correct |
22 |
Correct |
15 ms |
18900 KB |
Output is correct |
23 |
Correct |
15 ms |
18900 KB |
Output is correct |
24 |
Correct |
383 ms |
34780 KB |
Output is correct |
25 |
Correct |
381 ms |
40648 KB |
Output is correct |
26 |
Correct |
450 ms |
44728 KB |
Output is correct |
27 |
Correct |
447 ms |
44804 KB |
Output is correct |
28 |
Correct |
552 ms |
41776 KB |
Output is correct |
29 |
Correct |
506 ms |
42280 KB |
Output is correct |
30 |
Correct |
847 ms |
42688 KB |
Output is correct |
31 |
Correct |
256 ms |
31972 KB |
Output is correct |
32 |
Correct |
289 ms |
32048 KB |
Output is correct |
33 |
Correct |
455 ms |
40996 KB |
Output is correct |
34 |
Correct |
696 ms |
41932 KB |
Output is correct |
35 |
Correct |
763 ms |
39764 KB |
Output is correct |
36 |
Correct |
825 ms |
39868 KB |
Output is correct |
37 |
Correct |
474 ms |
44648 KB |
Output is correct |
38 |
Correct |
459 ms |
44716 KB |
Output is correct |
39 |
Correct |
582 ms |
44800 KB |
Output is correct |
40 |
Correct |
595 ms |
44924 KB |
Output is correct |
41 |
Correct |
8 ms |
18788 KB |
Output is correct |
42 |
Correct |
781 ms |
42528 KB |
Output is correct |
43 |
Correct |
453 ms |
40748 KB |
Output is correct |
44 |
Correct |
697 ms |
41700 KB |
Output is correct |
45 |
Correct |
803 ms |
36436 KB |
Output is correct |
46 |
Runtime error |
672 ms |
166128 KB |
Execution killed with signal 11 |
47 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
537 ms |
37196 KB |
Output is correct |
2 |
Correct |
570 ms |
35528 KB |
Output is correct |
3 |
Correct |
513 ms |
35368 KB |
Output is correct |
4 |
Correct |
406 ms |
35148 KB |
Output is correct |
5 |
Correct |
9 ms |
18772 KB |
Output is correct |
6 |
Correct |
553 ms |
34612 KB |
Output is correct |
7 |
Correct |
274 ms |
27192 KB |
Output is correct |
8 |
Correct |
299 ms |
27220 KB |
Output is correct |
9 |
Correct |
502 ms |
35244 KB |
Output is correct |
10 |
Correct |
573 ms |
38112 KB |
Output is correct |
11 |
Correct |
481 ms |
35460 KB |
Output is correct |
12 |
Correct |
8 ms |
18772 KB |
Output is correct |
13 |
Correct |
11 ms |
18768 KB |
Output is correct |
14 |
Correct |
9 ms |
18788 KB |
Output is correct |
15 |
Correct |
9 ms |
18728 KB |
Output is correct |
16 |
Correct |
8 ms |
18684 KB |
Output is correct |
17 |
Correct |
8 ms |
18772 KB |
Output is correct |
18 |
Correct |
10 ms |
18772 KB |
Output is correct |
19 |
Correct |
10 ms |
18724 KB |
Output is correct |
20 |
Correct |
9 ms |
18784 KB |
Output is correct |
21 |
Correct |
10 ms |
18772 KB |
Output is correct |
22 |
Correct |
9 ms |
18772 KB |
Output is correct |
23 |
Correct |
9 ms |
18776 KB |
Output is correct |
24 |
Correct |
9 ms |
18772 KB |
Output is correct |
25 |
Correct |
9 ms |
18704 KB |
Output is correct |
26 |
Correct |
9 ms |
18780 KB |
Output is correct |
27 |
Correct |
8 ms |
18780 KB |
Output is correct |
28 |
Correct |
13 ms |
19028 KB |
Output is correct |
29 |
Correct |
13 ms |
19028 KB |
Output is correct |
30 |
Correct |
15 ms |
19028 KB |
Output is correct |
31 |
Correct |
12 ms |
19028 KB |
Output is correct |
32 |
Correct |
16 ms |
19028 KB |
Output is correct |
33 |
Correct |
15 ms |
18900 KB |
Output is correct |
34 |
Correct |
15 ms |
18900 KB |
Output is correct |
35 |
Correct |
383 ms |
34780 KB |
Output is correct |
36 |
Correct |
381 ms |
40648 KB |
Output is correct |
37 |
Correct |
450 ms |
44728 KB |
Output is correct |
38 |
Correct |
447 ms |
44804 KB |
Output is correct |
39 |
Correct |
552 ms |
41776 KB |
Output is correct |
40 |
Correct |
506 ms |
42280 KB |
Output is correct |
41 |
Correct |
847 ms |
42688 KB |
Output is correct |
42 |
Correct |
256 ms |
31972 KB |
Output is correct |
43 |
Correct |
289 ms |
32048 KB |
Output is correct |
44 |
Correct |
455 ms |
40996 KB |
Output is correct |
45 |
Correct |
696 ms |
41932 KB |
Output is correct |
46 |
Correct |
763 ms |
39764 KB |
Output is correct |
47 |
Correct |
825 ms |
39868 KB |
Output is correct |
48 |
Correct |
474 ms |
44648 KB |
Output is correct |
49 |
Correct |
459 ms |
44716 KB |
Output is correct |
50 |
Correct |
582 ms |
44800 KB |
Output is correct |
51 |
Correct |
595 ms |
44924 KB |
Output is correct |
52 |
Correct |
8 ms |
18788 KB |
Output is correct |
53 |
Correct |
781 ms |
42528 KB |
Output is correct |
54 |
Correct |
453 ms |
40748 KB |
Output is correct |
55 |
Correct |
697 ms |
41700 KB |
Output is correct |
56 |
Correct |
803 ms |
36436 KB |
Output is correct |
57 |
Incorrect |
479 ms |
37544 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
537 ms |
37196 KB |
Output is correct |
2 |
Correct |
570 ms |
35528 KB |
Output is correct |
3 |
Correct |
513 ms |
35368 KB |
Output is correct |
4 |
Correct |
406 ms |
35148 KB |
Output is correct |
5 |
Correct |
9 ms |
18772 KB |
Output is correct |
6 |
Correct |
553 ms |
34612 KB |
Output is correct |
7 |
Correct |
274 ms |
27192 KB |
Output is correct |
8 |
Correct |
299 ms |
27220 KB |
Output is correct |
9 |
Correct |
502 ms |
35244 KB |
Output is correct |
10 |
Correct |
573 ms |
38112 KB |
Output is correct |
11 |
Correct |
481 ms |
35460 KB |
Output is correct |
12 |
Correct |
8 ms |
18772 KB |
Output is correct |
13 |
Correct |
11 ms |
18768 KB |
Output is correct |
14 |
Correct |
9 ms |
18788 KB |
Output is correct |
15 |
Correct |
9 ms |
18728 KB |
Output is correct |
16 |
Correct |
8 ms |
18684 KB |
Output is correct |
17 |
Correct |
8 ms |
18772 KB |
Output is correct |
18 |
Correct |
10 ms |
18772 KB |
Output is correct |
19 |
Correct |
10 ms |
18724 KB |
Output is correct |
20 |
Correct |
9 ms |
18784 KB |
Output is correct |
21 |
Correct |
10 ms |
18772 KB |
Output is correct |
22 |
Correct |
9 ms |
18772 KB |
Output is correct |
23 |
Correct |
9 ms |
18776 KB |
Output is correct |
24 |
Correct |
9 ms |
18772 KB |
Output is correct |
25 |
Correct |
9 ms |
18704 KB |
Output is correct |
26 |
Correct |
9 ms |
18780 KB |
Output is correct |
27 |
Correct |
8 ms |
18780 KB |
Output is correct |
28 |
Correct |
13 ms |
19028 KB |
Output is correct |
29 |
Correct |
13 ms |
19028 KB |
Output is correct |
30 |
Correct |
15 ms |
19028 KB |
Output is correct |
31 |
Correct |
12 ms |
19028 KB |
Output is correct |
32 |
Correct |
16 ms |
19028 KB |
Output is correct |
33 |
Correct |
15 ms |
18900 KB |
Output is correct |
34 |
Correct |
15 ms |
18900 KB |
Output is correct |
35 |
Correct |
383 ms |
34780 KB |
Output is correct |
36 |
Correct |
381 ms |
40648 KB |
Output is correct |
37 |
Correct |
450 ms |
44728 KB |
Output is correct |
38 |
Correct |
447 ms |
44804 KB |
Output is correct |
39 |
Correct |
552 ms |
41776 KB |
Output is correct |
40 |
Correct |
506 ms |
42280 KB |
Output is correct |
41 |
Correct |
847 ms |
42688 KB |
Output is correct |
42 |
Correct |
256 ms |
31972 KB |
Output is correct |
43 |
Correct |
289 ms |
32048 KB |
Output is correct |
44 |
Correct |
455 ms |
40996 KB |
Output is correct |
45 |
Correct |
696 ms |
41932 KB |
Output is correct |
46 |
Correct |
763 ms |
39764 KB |
Output is correct |
47 |
Correct |
825 ms |
39868 KB |
Output is correct |
48 |
Correct |
474 ms |
44648 KB |
Output is correct |
49 |
Correct |
459 ms |
44716 KB |
Output is correct |
50 |
Correct |
582 ms |
44800 KB |
Output is correct |
51 |
Correct |
595 ms |
44924 KB |
Output is correct |
52 |
Correct |
8 ms |
18788 KB |
Output is correct |
53 |
Correct |
781 ms |
42528 KB |
Output is correct |
54 |
Correct |
453 ms |
40748 KB |
Output is correct |
55 |
Correct |
697 ms |
41700 KB |
Output is correct |
56 |
Correct |
803 ms |
36436 KB |
Output is correct |
57 |
Runtime error |
672 ms |
166128 KB |
Execution killed with signal 11 |
58 |
Halted |
0 ms |
0 KB |
- |