#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1000005;
int n, m; ll upa[N], upb[N], val[N];
ll sa[N], sb[N], bda[N], bdb[N], pa[N], pb[N];
vector<pair<ll, ll>> stuff[N];
ll ans = 0; set<pair<ll, ll>> st;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i<=n; ++i) cin >> sa[i] >> bda[i] >> pa[i];
for(int i = 1; i<=m; ++i) cin >> sb[i] >> bdb[i] >> pb[i];
for(int i = 1; i<=n; ++i) sa[i] += sa[i-1];
for(int i = 1; i<=m; ++i) sb[i] += sb[i-1];
for(int i = 1; i<=n; ++i) upa[i] = upper_bound(sb, sb+m+1, bda[i]-sa[i])-sb-1;
for(int i = 1; i<=m; ++i) upb[i] = upper_bound(sa, sa+n+1, bdb[i]-sb[i])-sa-1;
for(int i = 1; i<=n; ++i) if(upa[i]+1<=m) stuff[i-1].push_back({upa[i]+1, -pa[i]});
for(int i = 1; i<=m; ++i) if(upb[i]>=0) stuff[upb[i]].push_back({i, pb[i]});
for(int i = 0; i<=n; ++i){
vector<int> pos;
for(auto [y, p] : stuff[i]){
if(y==0ll) ans += p;
else{
auto it = st.find({y, val[y]});
if(it!=st.end()) st.erase(it);
if((val[y] += p)<0) pos.push_back(y);
if(val[y]!=0) st.insert({y, val[y]});
}
}
for(auto y : pos) while(val[y]<0){
auto it = st.upper_bound({y, val[y]});
if(it==st.end()){
st.erase({y, val[y]});
val[y] = 0; continue;
}
int yy = it->first; st.erase(it);
st.erase({y, val[y]});
ll d = min(-val[y], val[yy]);
val[y] += d; val[yy] -= d;
if(val[y]!=0) st.insert({y, val[y]});
if(val[yy]!=0) st.insert({yy, val[yy]});
}
}
for(int i = 1; i<=n; ++i)
ans += pa[i];
for(auto [y, p] : st)
ans += p;
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
60120 KB |
Output is correct |
2 |
Correct |
399 ms |
50092 KB |
Output is correct |
3 |
Correct |
356 ms |
56392 KB |
Output is correct |
4 |
Correct |
303 ms |
55684 KB |
Output is correct |
5 |
Correct |
16 ms |
23796 KB |
Output is correct |
6 |
Correct |
338 ms |
51788 KB |
Output is correct |
7 |
Correct |
277 ms |
48568 KB |
Output is correct |
8 |
Correct |
145 ms |
32956 KB |
Output is correct |
9 |
Correct |
393 ms |
56416 KB |
Output is correct |
10 |
Correct |
341 ms |
50340 KB |
Output is correct |
11 |
Correct |
219 ms |
56520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
15 ms |
23796 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23812 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23804 KB |
Output is correct |
8 |
Correct |
17 ms |
23784 KB |
Output is correct |
9 |
Correct |
17 ms |
23780 KB |
Output is correct |
10 |
Correct |
20 ms |
23800 KB |
Output is correct |
11 |
Correct |
21 ms |
23756 KB |
Output is correct |
12 |
Correct |
19 ms |
23876 KB |
Output is correct |
13 |
Correct |
21 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23860 KB |
Output is correct |
15 |
Correct |
18 ms |
23836 KB |
Output is correct |
16 |
Correct |
19 ms |
23800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
15 ms |
23796 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23812 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23804 KB |
Output is correct |
8 |
Correct |
17 ms |
23784 KB |
Output is correct |
9 |
Correct |
17 ms |
23780 KB |
Output is correct |
10 |
Correct |
20 ms |
23800 KB |
Output is correct |
11 |
Correct |
21 ms |
23756 KB |
Output is correct |
12 |
Correct |
19 ms |
23876 KB |
Output is correct |
13 |
Correct |
21 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23860 KB |
Output is correct |
15 |
Correct |
18 ms |
23836 KB |
Output is correct |
16 |
Correct |
19 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
24172 KB |
Output is correct |
18 |
Correct |
24 ms |
24172 KB |
Output is correct |
19 |
Correct |
22 ms |
24200 KB |
Output is correct |
20 |
Correct |
20 ms |
24176 KB |
Output is correct |
21 |
Correct |
21 ms |
24192 KB |
Output is correct |
22 |
Correct |
20 ms |
24120 KB |
Output is correct |
23 |
Correct |
20 ms |
24124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
15 ms |
23796 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23812 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23804 KB |
Output is correct |
8 |
Correct |
17 ms |
23784 KB |
Output is correct |
9 |
Correct |
17 ms |
23780 KB |
Output is correct |
10 |
Correct |
20 ms |
23800 KB |
Output is correct |
11 |
Correct |
21 ms |
23756 KB |
Output is correct |
12 |
Correct |
19 ms |
23876 KB |
Output is correct |
13 |
Correct |
21 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23860 KB |
Output is correct |
15 |
Correct |
18 ms |
23836 KB |
Output is correct |
16 |
Correct |
19 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
24172 KB |
Output is correct |
18 |
Correct |
24 ms |
24172 KB |
Output is correct |
19 |
Correct |
22 ms |
24200 KB |
Output is correct |
20 |
Correct |
20 ms |
24176 KB |
Output is correct |
21 |
Correct |
21 ms |
24192 KB |
Output is correct |
22 |
Correct |
20 ms |
24120 KB |
Output is correct |
23 |
Correct |
20 ms |
24124 KB |
Output is correct |
24 |
Correct |
348 ms |
54820 KB |
Output is correct |
25 |
Correct |
314 ms |
59540 KB |
Output is correct |
26 |
Correct |
341 ms |
54772 KB |
Output is correct |
27 |
Correct |
324 ms |
61088 KB |
Output is correct |
28 |
Correct |
331 ms |
54096 KB |
Output is correct |
29 |
Correct |
311 ms |
56364 KB |
Output is correct |
30 |
Correct |
547 ms |
52396 KB |
Output is correct |
31 |
Correct |
187 ms |
50268 KB |
Output is correct |
32 |
Correct |
133 ms |
36208 KB |
Output is correct |
33 |
Correct |
433 ms |
50096 KB |
Output is correct |
34 |
Correct |
501 ms |
56804 KB |
Output is correct |
35 |
Correct |
532 ms |
52644 KB |
Output is correct |
36 |
Correct |
456 ms |
52540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
15 ms |
23796 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23812 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23804 KB |
Output is correct |
8 |
Correct |
17 ms |
23784 KB |
Output is correct |
9 |
Correct |
17 ms |
23780 KB |
Output is correct |
10 |
Correct |
20 ms |
23800 KB |
Output is correct |
11 |
Correct |
21 ms |
23756 KB |
Output is correct |
12 |
Correct |
19 ms |
23876 KB |
Output is correct |
13 |
Correct |
21 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23860 KB |
Output is correct |
15 |
Correct |
18 ms |
23836 KB |
Output is correct |
16 |
Correct |
19 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
24172 KB |
Output is correct |
18 |
Correct |
24 ms |
24172 KB |
Output is correct |
19 |
Correct |
22 ms |
24200 KB |
Output is correct |
20 |
Correct |
20 ms |
24176 KB |
Output is correct |
21 |
Correct |
21 ms |
24192 KB |
Output is correct |
22 |
Correct |
20 ms |
24120 KB |
Output is correct |
23 |
Correct |
20 ms |
24124 KB |
Output is correct |
24 |
Correct |
348 ms |
54820 KB |
Output is correct |
25 |
Correct |
314 ms |
59540 KB |
Output is correct |
26 |
Correct |
341 ms |
54772 KB |
Output is correct |
27 |
Correct |
324 ms |
61088 KB |
Output is correct |
28 |
Correct |
331 ms |
54096 KB |
Output is correct |
29 |
Correct |
311 ms |
56364 KB |
Output is correct |
30 |
Correct |
547 ms |
52396 KB |
Output is correct |
31 |
Correct |
187 ms |
50268 KB |
Output is correct |
32 |
Correct |
133 ms |
36208 KB |
Output is correct |
33 |
Correct |
433 ms |
50096 KB |
Output is correct |
34 |
Correct |
501 ms |
56804 KB |
Output is correct |
35 |
Correct |
532 ms |
52644 KB |
Output is correct |
36 |
Correct |
456 ms |
52540 KB |
Output is correct |
37 |
Correct |
421 ms |
54792 KB |
Output is correct |
38 |
Correct |
324 ms |
61108 KB |
Output is correct |
39 |
Correct |
457 ms |
62628 KB |
Output is correct |
40 |
Correct |
333 ms |
50208 KB |
Output is correct |
41 |
Correct |
16 ms |
23792 KB |
Output is correct |
42 |
Correct |
697 ms |
52384 KB |
Output is correct |
43 |
Correct |
494 ms |
49972 KB |
Output is correct |
44 |
Correct |
667 ms |
56604 KB |
Output is correct |
45 |
Correct |
710 ms |
52580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23796 KB |
Output is correct |
2 |
Correct |
15 ms |
23796 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23812 KB |
Output is correct |
5 |
Correct |
16 ms |
23808 KB |
Output is correct |
6 |
Correct |
20 ms |
23756 KB |
Output is correct |
7 |
Correct |
14 ms |
23804 KB |
Output is correct |
8 |
Correct |
17 ms |
23784 KB |
Output is correct |
9 |
Correct |
17 ms |
23780 KB |
Output is correct |
10 |
Correct |
20 ms |
23800 KB |
Output is correct |
11 |
Correct |
21 ms |
23756 KB |
Output is correct |
12 |
Correct |
19 ms |
23876 KB |
Output is correct |
13 |
Correct |
21 ms |
23800 KB |
Output is correct |
14 |
Correct |
20 ms |
23860 KB |
Output is correct |
15 |
Correct |
18 ms |
23836 KB |
Output is correct |
16 |
Correct |
19 ms |
23800 KB |
Output is correct |
17 |
Correct |
23 ms |
24172 KB |
Output is correct |
18 |
Correct |
24 ms |
24172 KB |
Output is correct |
19 |
Correct |
22 ms |
24200 KB |
Output is correct |
20 |
Correct |
20 ms |
24176 KB |
Output is correct |
21 |
Correct |
21 ms |
24192 KB |
Output is correct |
22 |
Correct |
20 ms |
24120 KB |
Output is correct |
23 |
Correct |
20 ms |
24124 KB |
Output is correct |
24 |
Correct |
348 ms |
54820 KB |
Output is correct |
25 |
Correct |
314 ms |
59540 KB |
Output is correct |
26 |
Correct |
341 ms |
54772 KB |
Output is correct |
27 |
Correct |
324 ms |
61088 KB |
Output is correct |
28 |
Correct |
331 ms |
54096 KB |
Output is correct |
29 |
Correct |
311 ms |
56364 KB |
Output is correct |
30 |
Correct |
547 ms |
52396 KB |
Output is correct |
31 |
Correct |
187 ms |
50268 KB |
Output is correct |
32 |
Correct |
133 ms |
36208 KB |
Output is correct |
33 |
Correct |
433 ms |
50096 KB |
Output is correct |
34 |
Correct |
501 ms |
56804 KB |
Output is correct |
35 |
Correct |
532 ms |
52644 KB |
Output is correct |
36 |
Correct |
456 ms |
52540 KB |
Output is correct |
37 |
Correct |
421 ms |
54792 KB |
Output is correct |
38 |
Correct |
324 ms |
61108 KB |
Output is correct |
39 |
Correct |
457 ms |
62628 KB |
Output is correct |
40 |
Correct |
333 ms |
50208 KB |
Output is correct |
41 |
Correct |
16 ms |
23792 KB |
Output is correct |
42 |
Correct |
697 ms |
52384 KB |
Output is correct |
43 |
Correct |
494 ms |
49972 KB |
Output is correct |
44 |
Correct |
667 ms |
56604 KB |
Output is correct |
45 |
Correct |
710 ms |
52580 KB |
Output is correct |
46 |
Correct |
1659 ms |
165020 KB |
Output is correct |
47 |
Correct |
1878 ms |
196296 KB |
Output is correct |
48 |
Correct |
2638 ms |
203896 KB |
Output is correct |
49 |
Correct |
1683 ms |
141460 KB |
Output is correct |
50 |
Correct |
3930 ms |
153184 KB |
Output is correct |
51 |
Correct |
2599 ms |
139608 KB |
Output is correct |
52 |
Correct |
3291 ms |
166280 KB |
Output is correct |
53 |
Correct |
3889 ms |
152888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
60120 KB |
Output is correct |
2 |
Correct |
399 ms |
50092 KB |
Output is correct |
3 |
Correct |
356 ms |
56392 KB |
Output is correct |
4 |
Correct |
303 ms |
55684 KB |
Output is correct |
5 |
Correct |
16 ms |
23796 KB |
Output is correct |
6 |
Correct |
338 ms |
51788 KB |
Output is correct |
7 |
Correct |
277 ms |
48568 KB |
Output is correct |
8 |
Correct |
145 ms |
32956 KB |
Output is correct |
9 |
Correct |
393 ms |
56416 KB |
Output is correct |
10 |
Correct |
341 ms |
50340 KB |
Output is correct |
11 |
Correct |
219 ms |
56520 KB |
Output is correct |
12 |
Correct |
14 ms |
23796 KB |
Output is correct |
13 |
Correct |
15 ms |
23796 KB |
Output is correct |
14 |
Correct |
16 ms |
23792 KB |
Output is correct |
15 |
Correct |
18 ms |
23812 KB |
Output is correct |
16 |
Correct |
16 ms |
23808 KB |
Output is correct |
17 |
Correct |
20 ms |
23756 KB |
Output is correct |
18 |
Correct |
14 ms |
23804 KB |
Output is correct |
19 |
Correct |
17 ms |
23784 KB |
Output is correct |
20 |
Correct |
17 ms |
23780 KB |
Output is correct |
21 |
Correct |
20 ms |
23800 KB |
Output is correct |
22 |
Correct |
21 ms |
23756 KB |
Output is correct |
23 |
Correct |
19 ms |
23876 KB |
Output is correct |
24 |
Correct |
21 ms |
23800 KB |
Output is correct |
25 |
Correct |
20 ms |
23860 KB |
Output is correct |
26 |
Correct |
18 ms |
23836 KB |
Output is correct |
27 |
Correct |
19 ms |
23800 KB |
Output is correct |
28 |
Correct |
23 ms |
24172 KB |
Output is correct |
29 |
Correct |
24 ms |
24172 KB |
Output is correct |
30 |
Correct |
22 ms |
24200 KB |
Output is correct |
31 |
Correct |
20 ms |
24176 KB |
Output is correct |
32 |
Correct |
21 ms |
24192 KB |
Output is correct |
33 |
Correct |
20 ms |
24120 KB |
Output is correct |
34 |
Correct |
20 ms |
24124 KB |
Output is correct |
35 |
Correct |
348 ms |
54820 KB |
Output is correct |
36 |
Correct |
314 ms |
59540 KB |
Output is correct |
37 |
Correct |
341 ms |
54772 KB |
Output is correct |
38 |
Correct |
324 ms |
61088 KB |
Output is correct |
39 |
Correct |
331 ms |
54096 KB |
Output is correct |
40 |
Correct |
311 ms |
56364 KB |
Output is correct |
41 |
Correct |
547 ms |
52396 KB |
Output is correct |
42 |
Correct |
187 ms |
50268 KB |
Output is correct |
43 |
Correct |
133 ms |
36208 KB |
Output is correct |
44 |
Correct |
433 ms |
50096 KB |
Output is correct |
45 |
Correct |
501 ms |
56804 KB |
Output is correct |
46 |
Correct |
532 ms |
52644 KB |
Output is correct |
47 |
Correct |
456 ms |
52540 KB |
Output is correct |
48 |
Correct |
421 ms |
54792 KB |
Output is correct |
49 |
Correct |
324 ms |
61108 KB |
Output is correct |
50 |
Correct |
457 ms |
62628 KB |
Output is correct |
51 |
Correct |
333 ms |
50208 KB |
Output is correct |
52 |
Correct |
16 ms |
23792 KB |
Output is correct |
53 |
Correct |
697 ms |
52384 KB |
Output is correct |
54 |
Correct |
494 ms |
49972 KB |
Output is correct |
55 |
Correct |
667 ms |
56604 KB |
Output is correct |
56 |
Correct |
710 ms |
52580 KB |
Output is correct |
57 |
Incorrect |
483 ms |
61588 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
60120 KB |
Output is correct |
2 |
Correct |
399 ms |
50092 KB |
Output is correct |
3 |
Correct |
356 ms |
56392 KB |
Output is correct |
4 |
Correct |
303 ms |
55684 KB |
Output is correct |
5 |
Correct |
16 ms |
23796 KB |
Output is correct |
6 |
Correct |
338 ms |
51788 KB |
Output is correct |
7 |
Correct |
277 ms |
48568 KB |
Output is correct |
8 |
Correct |
145 ms |
32956 KB |
Output is correct |
9 |
Correct |
393 ms |
56416 KB |
Output is correct |
10 |
Correct |
341 ms |
50340 KB |
Output is correct |
11 |
Correct |
219 ms |
56520 KB |
Output is correct |
12 |
Correct |
14 ms |
23796 KB |
Output is correct |
13 |
Correct |
15 ms |
23796 KB |
Output is correct |
14 |
Correct |
16 ms |
23792 KB |
Output is correct |
15 |
Correct |
18 ms |
23812 KB |
Output is correct |
16 |
Correct |
16 ms |
23808 KB |
Output is correct |
17 |
Correct |
20 ms |
23756 KB |
Output is correct |
18 |
Correct |
14 ms |
23804 KB |
Output is correct |
19 |
Correct |
17 ms |
23784 KB |
Output is correct |
20 |
Correct |
17 ms |
23780 KB |
Output is correct |
21 |
Correct |
20 ms |
23800 KB |
Output is correct |
22 |
Correct |
21 ms |
23756 KB |
Output is correct |
23 |
Correct |
19 ms |
23876 KB |
Output is correct |
24 |
Correct |
21 ms |
23800 KB |
Output is correct |
25 |
Correct |
20 ms |
23860 KB |
Output is correct |
26 |
Correct |
18 ms |
23836 KB |
Output is correct |
27 |
Correct |
19 ms |
23800 KB |
Output is correct |
28 |
Correct |
23 ms |
24172 KB |
Output is correct |
29 |
Correct |
24 ms |
24172 KB |
Output is correct |
30 |
Correct |
22 ms |
24200 KB |
Output is correct |
31 |
Correct |
20 ms |
24176 KB |
Output is correct |
32 |
Correct |
21 ms |
24192 KB |
Output is correct |
33 |
Correct |
20 ms |
24120 KB |
Output is correct |
34 |
Correct |
20 ms |
24124 KB |
Output is correct |
35 |
Correct |
348 ms |
54820 KB |
Output is correct |
36 |
Correct |
314 ms |
59540 KB |
Output is correct |
37 |
Correct |
341 ms |
54772 KB |
Output is correct |
38 |
Correct |
324 ms |
61088 KB |
Output is correct |
39 |
Correct |
331 ms |
54096 KB |
Output is correct |
40 |
Correct |
311 ms |
56364 KB |
Output is correct |
41 |
Correct |
547 ms |
52396 KB |
Output is correct |
42 |
Correct |
187 ms |
50268 KB |
Output is correct |
43 |
Correct |
133 ms |
36208 KB |
Output is correct |
44 |
Correct |
433 ms |
50096 KB |
Output is correct |
45 |
Correct |
501 ms |
56804 KB |
Output is correct |
46 |
Correct |
532 ms |
52644 KB |
Output is correct |
47 |
Correct |
456 ms |
52540 KB |
Output is correct |
48 |
Correct |
421 ms |
54792 KB |
Output is correct |
49 |
Correct |
324 ms |
61108 KB |
Output is correct |
50 |
Correct |
457 ms |
62628 KB |
Output is correct |
51 |
Correct |
333 ms |
50208 KB |
Output is correct |
52 |
Correct |
16 ms |
23792 KB |
Output is correct |
53 |
Correct |
697 ms |
52384 KB |
Output is correct |
54 |
Correct |
494 ms |
49972 KB |
Output is correct |
55 |
Correct |
667 ms |
56604 KB |
Output is correct |
56 |
Correct |
710 ms |
52580 KB |
Output is correct |
57 |
Correct |
1659 ms |
165020 KB |
Output is correct |
58 |
Correct |
1878 ms |
196296 KB |
Output is correct |
59 |
Correct |
2638 ms |
203896 KB |
Output is correct |
60 |
Correct |
1683 ms |
141460 KB |
Output is correct |
61 |
Correct |
3930 ms |
153184 KB |
Output is correct |
62 |
Correct |
2599 ms |
139608 KB |
Output is correct |
63 |
Correct |
3291 ms |
166280 KB |
Output is correct |
64 |
Correct |
3889 ms |
152888 KB |
Output is correct |
65 |
Incorrect |
483 ms |
61588 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |