#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);
val[y] += p; 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 |
293 ms |
59924 KB |
Output is correct |
2 |
Correct |
241 ms |
50148 KB |
Output is correct |
3 |
Correct |
237 ms |
54956 KB |
Output is correct |
4 |
Correct |
275 ms |
53444 KB |
Output is correct |
5 |
Correct |
13 ms |
23788 KB |
Output is correct |
6 |
Correct |
312 ms |
49768 KB |
Output is correct |
7 |
Correct |
167 ms |
46928 KB |
Output is correct |
8 |
Correct |
103 ms |
30604 KB |
Output is correct |
9 |
Correct |
247 ms |
54944 KB |
Output is correct |
10 |
Correct |
222 ms |
47948 KB |
Output is correct |
11 |
Correct |
204 ms |
54868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
14 ms |
23756 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23800 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23864 KB |
Output is correct |
12 |
Correct |
12 ms |
23744 KB |
Output is correct |
13 |
Correct |
12 ms |
23804 KB |
Output is correct |
14 |
Correct |
12 ms |
23804 KB |
Output is correct |
15 |
Correct |
15 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
14 ms |
23756 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23800 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23864 KB |
Output is correct |
12 |
Correct |
12 ms |
23744 KB |
Output is correct |
13 |
Correct |
12 ms |
23804 KB |
Output is correct |
14 |
Correct |
12 ms |
23804 KB |
Output is correct |
15 |
Correct |
15 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23804 KB |
Output is correct |
17 |
Correct |
14 ms |
24236 KB |
Output is correct |
18 |
Correct |
15 ms |
24180 KB |
Output is correct |
19 |
Correct |
15 ms |
24236 KB |
Output is correct |
20 |
Correct |
16 ms |
24104 KB |
Output is correct |
21 |
Correct |
16 ms |
24196 KB |
Output is correct |
22 |
Correct |
17 ms |
24052 KB |
Output is correct |
23 |
Correct |
15 ms |
24176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
14 ms |
23756 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23800 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23864 KB |
Output is correct |
12 |
Correct |
12 ms |
23744 KB |
Output is correct |
13 |
Correct |
12 ms |
23804 KB |
Output is correct |
14 |
Correct |
12 ms |
23804 KB |
Output is correct |
15 |
Correct |
15 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23804 KB |
Output is correct |
17 |
Correct |
14 ms |
24236 KB |
Output is correct |
18 |
Correct |
15 ms |
24180 KB |
Output is correct |
19 |
Correct |
15 ms |
24236 KB |
Output is correct |
20 |
Correct |
16 ms |
24104 KB |
Output is correct |
21 |
Correct |
16 ms |
24196 KB |
Output is correct |
22 |
Correct |
17 ms |
24052 KB |
Output is correct |
23 |
Correct |
15 ms |
24176 KB |
Output is correct |
24 |
Correct |
272 ms |
52980 KB |
Output is correct |
25 |
Correct |
234 ms |
58028 KB |
Output is correct |
26 |
Correct |
223 ms |
52924 KB |
Output is correct |
27 |
Correct |
256 ms |
58784 KB |
Output is correct |
28 |
Correct |
238 ms |
52436 KB |
Output is correct |
29 |
Correct |
240 ms |
54964 KB |
Output is correct |
30 |
Correct |
441 ms |
50168 KB |
Output is correct |
31 |
Correct |
150 ms |
48200 KB |
Output is correct |
32 |
Correct |
113 ms |
33820 KB |
Output is correct |
33 |
Correct |
313 ms |
47820 KB |
Output is correct |
34 |
Correct |
421 ms |
54716 KB |
Output is correct |
35 |
Correct |
375 ms |
50264 KB |
Output is correct |
36 |
Correct |
397 ms |
50244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
14 ms |
23756 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23800 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23864 KB |
Output is correct |
12 |
Correct |
12 ms |
23744 KB |
Output is correct |
13 |
Correct |
12 ms |
23804 KB |
Output is correct |
14 |
Correct |
12 ms |
23804 KB |
Output is correct |
15 |
Correct |
15 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23804 KB |
Output is correct |
17 |
Correct |
14 ms |
24236 KB |
Output is correct |
18 |
Correct |
15 ms |
24180 KB |
Output is correct |
19 |
Correct |
15 ms |
24236 KB |
Output is correct |
20 |
Correct |
16 ms |
24104 KB |
Output is correct |
21 |
Correct |
16 ms |
24196 KB |
Output is correct |
22 |
Correct |
17 ms |
24052 KB |
Output is correct |
23 |
Correct |
15 ms |
24176 KB |
Output is correct |
24 |
Correct |
272 ms |
52980 KB |
Output is correct |
25 |
Correct |
234 ms |
58028 KB |
Output is correct |
26 |
Correct |
223 ms |
52924 KB |
Output is correct |
27 |
Correct |
256 ms |
58784 KB |
Output is correct |
28 |
Correct |
238 ms |
52436 KB |
Output is correct |
29 |
Correct |
240 ms |
54964 KB |
Output is correct |
30 |
Correct |
441 ms |
50168 KB |
Output is correct |
31 |
Correct |
150 ms |
48200 KB |
Output is correct |
32 |
Correct |
113 ms |
33820 KB |
Output is correct |
33 |
Correct |
313 ms |
47820 KB |
Output is correct |
34 |
Correct |
421 ms |
54716 KB |
Output is correct |
35 |
Correct |
375 ms |
50264 KB |
Output is correct |
36 |
Correct |
397 ms |
50244 KB |
Output is correct |
37 |
Correct |
249 ms |
52976 KB |
Output is correct |
38 |
Correct |
270 ms |
58828 KB |
Output is correct |
39 |
Correct |
440 ms |
60380 KB |
Output is correct |
40 |
Correct |
245 ms |
47940 KB |
Output is correct |
41 |
Correct |
11 ms |
23800 KB |
Output is correct |
42 |
Correct |
553 ms |
50128 KB |
Output is correct |
43 |
Correct |
405 ms |
47784 KB |
Output is correct |
44 |
Correct |
420 ms |
54552 KB |
Output is correct |
45 |
Correct |
518 ms |
50196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23796 KB |
Output is correct |
3 |
Correct |
14 ms |
23756 KB |
Output is correct |
4 |
Correct |
14 ms |
23808 KB |
Output is correct |
5 |
Correct |
17 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
14 ms |
23756 KB |
Output is correct |
8 |
Correct |
13 ms |
23804 KB |
Output is correct |
9 |
Correct |
13 ms |
23800 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23864 KB |
Output is correct |
12 |
Correct |
12 ms |
23744 KB |
Output is correct |
13 |
Correct |
12 ms |
23804 KB |
Output is correct |
14 |
Correct |
12 ms |
23804 KB |
Output is correct |
15 |
Correct |
15 ms |
23788 KB |
Output is correct |
16 |
Correct |
17 ms |
23804 KB |
Output is correct |
17 |
Correct |
14 ms |
24236 KB |
Output is correct |
18 |
Correct |
15 ms |
24180 KB |
Output is correct |
19 |
Correct |
15 ms |
24236 KB |
Output is correct |
20 |
Correct |
16 ms |
24104 KB |
Output is correct |
21 |
Correct |
16 ms |
24196 KB |
Output is correct |
22 |
Correct |
17 ms |
24052 KB |
Output is correct |
23 |
Correct |
15 ms |
24176 KB |
Output is correct |
24 |
Correct |
272 ms |
52980 KB |
Output is correct |
25 |
Correct |
234 ms |
58028 KB |
Output is correct |
26 |
Correct |
223 ms |
52924 KB |
Output is correct |
27 |
Correct |
256 ms |
58784 KB |
Output is correct |
28 |
Correct |
238 ms |
52436 KB |
Output is correct |
29 |
Correct |
240 ms |
54964 KB |
Output is correct |
30 |
Correct |
441 ms |
50168 KB |
Output is correct |
31 |
Correct |
150 ms |
48200 KB |
Output is correct |
32 |
Correct |
113 ms |
33820 KB |
Output is correct |
33 |
Correct |
313 ms |
47820 KB |
Output is correct |
34 |
Correct |
421 ms |
54716 KB |
Output is correct |
35 |
Correct |
375 ms |
50264 KB |
Output is correct |
36 |
Correct |
397 ms |
50244 KB |
Output is correct |
37 |
Correct |
249 ms |
52976 KB |
Output is correct |
38 |
Correct |
270 ms |
58828 KB |
Output is correct |
39 |
Correct |
440 ms |
60380 KB |
Output is correct |
40 |
Correct |
245 ms |
47940 KB |
Output is correct |
41 |
Correct |
11 ms |
23800 KB |
Output is correct |
42 |
Correct |
553 ms |
50128 KB |
Output is correct |
43 |
Correct |
405 ms |
47784 KB |
Output is correct |
44 |
Correct |
420 ms |
54552 KB |
Output is correct |
45 |
Correct |
518 ms |
50196 KB |
Output is correct |
46 |
Correct |
1340 ms |
167284 KB |
Output is correct |
47 |
Correct |
1585 ms |
196764 KB |
Output is correct |
48 |
Correct |
2293 ms |
204208 KB |
Output is correct |
49 |
Correct |
1042 ms |
141708 KB |
Output is correct |
50 |
Correct |
3433 ms |
154104 KB |
Output is correct |
51 |
Correct |
2158 ms |
140432 KB |
Output is correct |
52 |
Correct |
2588 ms |
167184 KB |
Output is correct |
53 |
Correct |
3087 ms |
153216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
293 ms |
59924 KB |
Output is correct |
2 |
Correct |
241 ms |
50148 KB |
Output is correct |
3 |
Correct |
237 ms |
54956 KB |
Output is correct |
4 |
Correct |
275 ms |
53444 KB |
Output is correct |
5 |
Correct |
13 ms |
23788 KB |
Output is correct |
6 |
Correct |
312 ms |
49768 KB |
Output is correct |
7 |
Correct |
167 ms |
46928 KB |
Output is correct |
8 |
Correct |
103 ms |
30604 KB |
Output is correct |
9 |
Correct |
247 ms |
54944 KB |
Output is correct |
10 |
Correct |
222 ms |
47948 KB |
Output is correct |
11 |
Correct |
204 ms |
54868 KB |
Output is correct |
12 |
Correct |
13 ms |
23756 KB |
Output is correct |
13 |
Correct |
14 ms |
23796 KB |
Output is correct |
14 |
Correct |
14 ms |
23756 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23820 KB |
Output is correct |
17 |
Correct |
13 ms |
23792 KB |
Output is correct |
18 |
Correct |
14 ms |
23756 KB |
Output is correct |
19 |
Correct |
13 ms |
23804 KB |
Output is correct |
20 |
Correct |
13 ms |
23800 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
14 ms |
23864 KB |
Output is correct |
23 |
Correct |
12 ms |
23744 KB |
Output is correct |
24 |
Correct |
12 ms |
23804 KB |
Output is correct |
25 |
Correct |
12 ms |
23804 KB |
Output is correct |
26 |
Correct |
15 ms |
23788 KB |
Output is correct |
27 |
Correct |
17 ms |
23804 KB |
Output is correct |
28 |
Correct |
14 ms |
24236 KB |
Output is correct |
29 |
Correct |
15 ms |
24180 KB |
Output is correct |
30 |
Correct |
15 ms |
24236 KB |
Output is correct |
31 |
Correct |
16 ms |
24104 KB |
Output is correct |
32 |
Correct |
16 ms |
24196 KB |
Output is correct |
33 |
Correct |
17 ms |
24052 KB |
Output is correct |
34 |
Correct |
15 ms |
24176 KB |
Output is correct |
35 |
Correct |
272 ms |
52980 KB |
Output is correct |
36 |
Correct |
234 ms |
58028 KB |
Output is correct |
37 |
Correct |
223 ms |
52924 KB |
Output is correct |
38 |
Correct |
256 ms |
58784 KB |
Output is correct |
39 |
Correct |
238 ms |
52436 KB |
Output is correct |
40 |
Correct |
240 ms |
54964 KB |
Output is correct |
41 |
Correct |
441 ms |
50168 KB |
Output is correct |
42 |
Correct |
150 ms |
48200 KB |
Output is correct |
43 |
Correct |
113 ms |
33820 KB |
Output is correct |
44 |
Correct |
313 ms |
47820 KB |
Output is correct |
45 |
Correct |
421 ms |
54716 KB |
Output is correct |
46 |
Correct |
375 ms |
50264 KB |
Output is correct |
47 |
Correct |
397 ms |
50244 KB |
Output is correct |
48 |
Correct |
249 ms |
52976 KB |
Output is correct |
49 |
Correct |
270 ms |
58828 KB |
Output is correct |
50 |
Correct |
440 ms |
60380 KB |
Output is correct |
51 |
Correct |
245 ms |
47940 KB |
Output is correct |
52 |
Correct |
11 ms |
23800 KB |
Output is correct |
53 |
Correct |
553 ms |
50128 KB |
Output is correct |
54 |
Correct |
405 ms |
47784 KB |
Output is correct |
55 |
Correct |
420 ms |
54552 KB |
Output is correct |
56 |
Correct |
518 ms |
50196 KB |
Output is correct |
57 |
Incorrect |
348 ms |
60748 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
293 ms |
59924 KB |
Output is correct |
2 |
Correct |
241 ms |
50148 KB |
Output is correct |
3 |
Correct |
237 ms |
54956 KB |
Output is correct |
4 |
Correct |
275 ms |
53444 KB |
Output is correct |
5 |
Correct |
13 ms |
23788 KB |
Output is correct |
6 |
Correct |
312 ms |
49768 KB |
Output is correct |
7 |
Correct |
167 ms |
46928 KB |
Output is correct |
8 |
Correct |
103 ms |
30604 KB |
Output is correct |
9 |
Correct |
247 ms |
54944 KB |
Output is correct |
10 |
Correct |
222 ms |
47948 KB |
Output is correct |
11 |
Correct |
204 ms |
54868 KB |
Output is correct |
12 |
Correct |
13 ms |
23756 KB |
Output is correct |
13 |
Correct |
14 ms |
23796 KB |
Output is correct |
14 |
Correct |
14 ms |
23756 KB |
Output is correct |
15 |
Correct |
14 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23820 KB |
Output is correct |
17 |
Correct |
13 ms |
23792 KB |
Output is correct |
18 |
Correct |
14 ms |
23756 KB |
Output is correct |
19 |
Correct |
13 ms |
23804 KB |
Output is correct |
20 |
Correct |
13 ms |
23800 KB |
Output is correct |
21 |
Correct |
13 ms |
23764 KB |
Output is correct |
22 |
Correct |
14 ms |
23864 KB |
Output is correct |
23 |
Correct |
12 ms |
23744 KB |
Output is correct |
24 |
Correct |
12 ms |
23804 KB |
Output is correct |
25 |
Correct |
12 ms |
23804 KB |
Output is correct |
26 |
Correct |
15 ms |
23788 KB |
Output is correct |
27 |
Correct |
17 ms |
23804 KB |
Output is correct |
28 |
Correct |
14 ms |
24236 KB |
Output is correct |
29 |
Correct |
15 ms |
24180 KB |
Output is correct |
30 |
Correct |
15 ms |
24236 KB |
Output is correct |
31 |
Correct |
16 ms |
24104 KB |
Output is correct |
32 |
Correct |
16 ms |
24196 KB |
Output is correct |
33 |
Correct |
17 ms |
24052 KB |
Output is correct |
34 |
Correct |
15 ms |
24176 KB |
Output is correct |
35 |
Correct |
272 ms |
52980 KB |
Output is correct |
36 |
Correct |
234 ms |
58028 KB |
Output is correct |
37 |
Correct |
223 ms |
52924 KB |
Output is correct |
38 |
Correct |
256 ms |
58784 KB |
Output is correct |
39 |
Correct |
238 ms |
52436 KB |
Output is correct |
40 |
Correct |
240 ms |
54964 KB |
Output is correct |
41 |
Correct |
441 ms |
50168 KB |
Output is correct |
42 |
Correct |
150 ms |
48200 KB |
Output is correct |
43 |
Correct |
113 ms |
33820 KB |
Output is correct |
44 |
Correct |
313 ms |
47820 KB |
Output is correct |
45 |
Correct |
421 ms |
54716 KB |
Output is correct |
46 |
Correct |
375 ms |
50264 KB |
Output is correct |
47 |
Correct |
397 ms |
50244 KB |
Output is correct |
48 |
Correct |
249 ms |
52976 KB |
Output is correct |
49 |
Correct |
270 ms |
58828 KB |
Output is correct |
50 |
Correct |
440 ms |
60380 KB |
Output is correct |
51 |
Correct |
245 ms |
47940 KB |
Output is correct |
52 |
Correct |
11 ms |
23800 KB |
Output is correct |
53 |
Correct |
553 ms |
50128 KB |
Output is correct |
54 |
Correct |
405 ms |
47784 KB |
Output is correct |
55 |
Correct |
420 ms |
54552 KB |
Output is correct |
56 |
Correct |
518 ms |
50196 KB |
Output is correct |
57 |
Correct |
1340 ms |
167284 KB |
Output is correct |
58 |
Correct |
1585 ms |
196764 KB |
Output is correct |
59 |
Correct |
2293 ms |
204208 KB |
Output is correct |
60 |
Correct |
1042 ms |
141708 KB |
Output is correct |
61 |
Correct |
3433 ms |
154104 KB |
Output is correct |
62 |
Correct |
2158 ms |
140432 KB |
Output is correct |
63 |
Correct |
2588 ms |
167184 KB |
Output is correct |
64 |
Correct |
3087 ms |
153216 KB |
Output is correct |
65 |
Incorrect |
348 ms |
60748 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |