#include "bits/stdc++.h"
using namespace std;
#define int long long
vector<pair<int,int>> lol[1000001];
int arr1[1000001] = {0};
int arr2[1000001] = {0};
int a[1000001];int s[1000001];int p[1000001];
int b[1000001];int t[1000001];int q[1000001];
signed main(){
int n,m;
cin>>n>>m;
for(int i = 1;i<=n;i++){
cin>>a[i]>>s[i]>>p[i];
arr1[i] = a[i]+arr1[i-1];
}
for(int i = 1;i<=m;i++){
cin>>b[i]>>t[i]>>q[i];
arr2[i] = b[i]+arr2[i-1];
}
for(int i = 1;i<=n;i++){
int l = 0 , r = m , ans = -1;
while(l<=r){
int mid = (l+r)/2;
if(arr2[mid]+arr1[i]<=s[i]){
ans = mid;l = mid+1;
}else r = mid-1;
}
if(ans==-1)continue;
lol[ans].push_back({i,p[i]});
}
long long all = 0;
for(int i = 1;i<=m;i++){
int l = 0 , r = n , ans = -1;
while(l<=r){
int mid = (l+r)/2;
if(arr2[i]+arr1[mid]<=t[i]){
ans = mid;l = mid+1;
}else r = mid-1;
}
if(ans==-1)continue;
if(ans!=n)lol[i-1].push_back({ans+1,-q[i]});
all+=q[i];
}
map<int,int> mp;
for(int i = 0;i<=m;i++){
for(auto j:lol[i]){
if(j.second>=0||i==m){
mp[j.first]+=j.second;
continue;
}
int ans = j.second;
auto it = mp.lower_bound(j.first);
while(it!=mp.end()){
if(ans+(*it).second>=0){
mp[(*it).first]+=ans;
ans = 0;
break;
}
ans+=(*it).second;
it = mp.erase(it);
}
}
}
for(auto i:mp)all+=i.second;
cout<<all<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
59988 KB |
Output is correct |
2 |
Correct |
391 ms |
70244 KB |
Output is correct |
3 |
Correct |
374 ms |
66232 KB |
Output is correct |
4 |
Correct |
350 ms |
56664 KB |
Output is correct |
5 |
Correct |
6 ms |
34908 KB |
Output is correct |
6 |
Correct |
378 ms |
62064 KB |
Output is correct |
7 |
Correct |
166 ms |
43604 KB |
Output is correct |
8 |
Correct |
205 ms |
57748 KB |
Output is correct |
9 |
Correct |
399 ms |
67000 KB |
Output is correct |
10 |
Correct |
241 ms |
59984 KB |
Output is correct |
11 |
Correct |
248 ms |
66228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
34908 KB |
Output is correct |
2 |
Correct |
5 ms |
34908 KB |
Output is correct |
3 |
Correct |
5 ms |
34908 KB |
Output is correct |
4 |
Correct |
5 ms |
34908 KB |
Output is correct |
5 |
Correct |
5 ms |
34908 KB |
Output is correct |
6 |
Correct |
5 ms |
35076 KB |
Output is correct |
7 |
Correct |
5 ms |
34908 KB |
Output is correct |
8 |
Correct |
5 ms |
35056 KB |
Output is correct |
9 |
Correct |
5 ms |
34908 KB |
Output is correct |
10 |
Correct |
5 ms |
34908 KB |
Output is correct |
11 |
Correct |
5 ms |
34908 KB |
Output is correct |
12 |
Correct |
6 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
7 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34904 KB |
Output is correct |
16 |
Correct |
5 ms |
35032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
34908 KB |
Output is correct |
2 |
Correct |
5 ms |
34908 KB |
Output is correct |
3 |
Correct |
5 ms |
34908 KB |
Output is correct |
4 |
Correct |
5 ms |
34908 KB |
Output is correct |
5 |
Correct |
5 ms |
34908 KB |
Output is correct |
6 |
Correct |
5 ms |
35076 KB |
Output is correct |
7 |
Correct |
5 ms |
34908 KB |
Output is correct |
8 |
Correct |
5 ms |
35056 KB |
Output is correct |
9 |
Correct |
5 ms |
34908 KB |
Output is correct |
10 |
Correct |
5 ms |
34908 KB |
Output is correct |
11 |
Correct |
5 ms |
34908 KB |
Output is correct |
12 |
Correct |
6 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
7 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34904 KB |
Output is correct |
16 |
Correct |
5 ms |
35032 KB |
Output is correct |
17 |
Correct |
8 ms |
35160 KB |
Output is correct |
18 |
Correct |
8 ms |
35160 KB |
Output is correct |
19 |
Correct |
8 ms |
35160 KB |
Output is correct |
20 |
Correct |
8 ms |
35164 KB |
Output is correct |
21 |
Correct |
8 ms |
35164 KB |
Output is correct |
22 |
Correct |
7 ms |
35052 KB |
Output is correct |
23 |
Correct |
7 ms |
35164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
34908 KB |
Output is correct |
2 |
Correct |
5 ms |
34908 KB |
Output is correct |
3 |
Correct |
5 ms |
34908 KB |
Output is correct |
4 |
Correct |
5 ms |
34908 KB |
Output is correct |
5 |
Correct |
5 ms |
34908 KB |
Output is correct |
6 |
Correct |
5 ms |
35076 KB |
Output is correct |
7 |
Correct |
5 ms |
34908 KB |
Output is correct |
8 |
Correct |
5 ms |
35056 KB |
Output is correct |
9 |
Correct |
5 ms |
34908 KB |
Output is correct |
10 |
Correct |
5 ms |
34908 KB |
Output is correct |
11 |
Correct |
5 ms |
34908 KB |
Output is correct |
12 |
Correct |
6 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
7 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34904 KB |
Output is correct |
16 |
Correct |
5 ms |
35032 KB |
Output is correct |
17 |
Correct |
8 ms |
35160 KB |
Output is correct |
18 |
Correct |
8 ms |
35160 KB |
Output is correct |
19 |
Correct |
8 ms |
35160 KB |
Output is correct |
20 |
Correct |
8 ms |
35164 KB |
Output is correct |
21 |
Correct |
8 ms |
35164 KB |
Output is correct |
22 |
Correct |
7 ms |
35052 KB |
Output is correct |
23 |
Correct |
7 ms |
35164 KB |
Output is correct |
24 |
Correct |
315 ms |
66232 KB |
Output is correct |
25 |
Correct |
309 ms |
64704 KB |
Output is correct |
26 |
Correct |
339 ms |
69460 KB |
Output is correct |
27 |
Correct |
309 ms |
64868 KB |
Output is correct |
28 |
Correct |
353 ms |
63304 KB |
Output is correct |
29 |
Correct |
356 ms |
66876 KB |
Output is correct |
30 |
Correct |
414 ms |
61016 KB |
Output is correct |
31 |
Correct |
144 ms |
46932 KB |
Output is correct |
32 |
Correct |
184 ms |
57604 KB |
Output is correct |
33 |
Correct |
327 ms |
56144 KB |
Output is correct |
34 |
Correct |
382 ms |
67700 KB |
Output is correct |
35 |
Correct |
260 ms |
60916 KB |
Output is correct |
36 |
Correct |
249 ms |
61012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
34908 KB |
Output is correct |
2 |
Correct |
5 ms |
34908 KB |
Output is correct |
3 |
Correct |
5 ms |
34908 KB |
Output is correct |
4 |
Correct |
5 ms |
34908 KB |
Output is correct |
5 |
Correct |
5 ms |
34908 KB |
Output is correct |
6 |
Correct |
5 ms |
35076 KB |
Output is correct |
7 |
Correct |
5 ms |
34908 KB |
Output is correct |
8 |
Correct |
5 ms |
35056 KB |
Output is correct |
9 |
Correct |
5 ms |
34908 KB |
Output is correct |
10 |
Correct |
5 ms |
34908 KB |
Output is correct |
11 |
Correct |
5 ms |
34908 KB |
Output is correct |
12 |
Correct |
6 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
7 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34904 KB |
Output is correct |
16 |
Correct |
5 ms |
35032 KB |
Output is correct |
17 |
Correct |
8 ms |
35160 KB |
Output is correct |
18 |
Correct |
8 ms |
35160 KB |
Output is correct |
19 |
Correct |
8 ms |
35160 KB |
Output is correct |
20 |
Correct |
8 ms |
35164 KB |
Output is correct |
21 |
Correct |
8 ms |
35164 KB |
Output is correct |
22 |
Correct |
7 ms |
35052 KB |
Output is correct |
23 |
Correct |
7 ms |
35164 KB |
Output is correct |
24 |
Correct |
315 ms |
66232 KB |
Output is correct |
25 |
Correct |
309 ms |
64704 KB |
Output is correct |
26 |
Correct |
339 ms |
69460 KB |
Output is correct |
27 |
Correct |
309 ms |
64868 KB |
Output is correct |
28 |
Correct |
353 ms |
63304 KB |
Output is correct |
29 |
Correct |
356 ms |
66876 KB |
Output is correct |
30 |
Correct |
414 ms |
61016 KB |
Output is correct |
31 |
Correct |
144 ms |
46932 KB |
Output is correct |
32 |
Correct |
184 ms |
57604 KB |
Output is correct |
33 |
Correct |
327 ms |
56144 KB |
Output is correct |
34 |
Correct |
382 ms |
67700 KB |
Output is correct |
35 |
Correct |
260 ms |
60916 KB |
Output is correct |
36 |
Correct |
249 ms |
61012 KB |
Output is correct |
37 |
Correct |
373 ms |
69456 KB |
Output is correct |
38 |
Correct |
350 ms |
64712 KB |
Output is correct |
39 |
Correct |
305 ms |
59972 KB |
Output is correct |
40 |
Correct |
385 ms |
72532 KB |
Output is correct |
41 |
Correct |
5 ms |
34908 KB |
Output is correct |
42 |
Correct |
441 ms |
60756 KB |
Output is correct |
43 |
Correct |
441 ms |
54812 KB |
Output is correct |
44 |
Correct |
449 ms |
67784 KB |
Output is correct |
45 |
Correct |
334 ms |
60888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
34908 KB |
Output is correct |
2 |
Correct |
5 ms |
34908 KB |
Output is correct |
3 |
Correct |
5 ms |
34908 KB |
Output is correct |
4 |
Correct |
5 ms |
34908 KB |
Output is correct |
5 |
Correct |
5 ms |
34908 KB |
Output is correct |
6 |
Correct |
5 ms |
35076 KB |
Output is correct |
7 |
Correct |
5 ms |
34908 KB |
Output is correct |
8 |
Correct |
5 ms |
35056 KB |
Output is correct |
9 |
Correct |
5 ms |
34908 KB |
Output is correct |
10 |
Correct |
5 ms |
34908 KB |
Output is correct |
11 |
Correct |
5 ms |
34908 KB |
Output is correct |
12 |
Correct |
6 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
7 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34904 KB |
Output is correct |
16 |
Correct |
5 ms |
35032 KB |
Output is correct |
17 |
Correct |
8 ms |
35160 KB |
Output is correct |
18 |
Correct |
8 ms |
35160 KB |
Output is correct |
19 |
Correct |
8 ms |
35160 KB |
Output is correct |
20 |
Correct |
8 ms |
35164 KB |
Output is correct |
21 |
Correct |
8 ms |
35164 KB |
Output is correct |
22 |
Correct |
7 ms |
35052 KB |
Output is correct |
23 |
Correct |
7 ms |
35164 KB |
Output is correct |
24 |
Correct |
315 ms |
66232 KB |
Output is correct |
25 |
Correct |
309 ms |
64704 KB |
Output is correct |
26 |
Correct |
339 ms |
69460 KB |
Output is correct |
27 |
Correct |
309 ms |
64868 KB |
Output is correct |
28 |
Correct |
353 ms |
63304 KB |
Output is correct |
29 |
Correct |
356 ms |
66876 KB |
Output is correct |
30 |
Correct |
414 ms |
61016 KB |
Output is correct |
31 |
Correct |
144 ms |
46932 KB |
Output is correct |
32 |
Correct |
184 ms |
57604 KB |
Output is correct |
33 |
Correct |
327 ms |
56144 KB |
Output is correct |
34 |
Correct |
382 ms |
67700 KB |
Output is correct |
35 |
Correct |
260 ms |
60916 KB |
Output is correct |
36 |
Correct |
249 ms |
61012 KB |
Output is correct |
37 |
Correct |
373 ms |
69456 KB |
Output is correct |
38 |
Correct |
350 ms |
64712 KB |
Output is correct |
39 |
Correct |
305 ms |
59972 KB |
Output is correct |
40 |
Correct |
385 ms |
72532 KB |
Output is correct |
41 |
Correct |
5 ms |
34908 KB |
Output is correct |
42 |
Correct |
441 ms |
60756 KB |
Output is correct |
43 |
Correct |
441 ms |
54812 KB |
Output is correct |
44 |
Correct |
449 ms |
67784 KB |
Output is correct |
45 |
Correct |
334 ms |
60888 KB |
Output is correct |
46 |
Correct |
2084 ms |
180468 KB |
Output is correct |
47 |
Correct |
1840 ms |
156976 KB |
Output is correct |
48 |
Correct |
1675 ms |
133388 KB |
Output is correct |
49 |
Correct |
2145 ms |
195928 KB |
Output is correct |
50 |
Correct |
2569 ms |
137344 KB |
Output is correct |
51 |
Correct |
2060 ms |
112436 KB |
Output is correct |
52 |
Correct |
2297 ms |
171100 KB |
Output is correct |
53 |
Correct |
1923 ms |
136996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
59988 KB |
Output is correct |
2 |
Correct |
391 ms |
70244 KB |
Output is correct |
3 |
Correct |
374 ms |
66232 KB |
Output is correct |
4 |
Correct |
350 ms |
56664 KB |
Output is correct |
5 |
Correct |
6 ms |
34908 KB |
Output is correct |
6 |
Correct |
378 ms |
62064 KB |
Output is correct |
7 |
Correct |
166 ms |
43604 KB |
Output is correct |
8 |
Correct |
205 ms |
57748 KB |
Output is correct |
9 |
Correct |
399 ms |
67000 KB |
Output is correct |
10 |
Correct |
241 ms |
59984 KB |
Output is correct |
11 |
Correct |
248 ms |
66228 KB |
Output is correct |
12 |
Correct |
5 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
5 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34908 KB |
Output is correct |
16 |
Correct |
5 ms |
34908 KB |
Output is correct |
17 |
Correct |
5 ms |
35076 KB |
Output is correct |
18 |
Correct |
5 ms |
34908 KB |
Output is correct |
19 |
Correct |
5 ms |
35056 KB |
Output is correct |
20 |
Correct |
5 ms |
34908 KB |
Output is correct |
21 |
Correct |
5 ms |
34908 KB |
Output is correct |
22 |
Correct |
5 ms |
34908 KB |
Output is correct |
23 |
Correct |
6 ms |
34908 KB |
Output is correct |
24 |
Correct |
5 ms |
34908 KB |
Output is correct |
25 |
Correct |
7 ms |
34908 KB |
Output is correct |
26 |
Correct |
5 ms |
34904 KB |
Output is correct |
27 |
Correct |
5 ms |
35032 KB |
Output is correct |
28 |
Correct |
8 ms |
35160 KB |
Output is correct |
29 |
Correct |
8 ms |
35160 KB |
Output is correct |
30 |
Correct |
8 ms |
35160 KB |
Output is correct |
31 |
Correct |
8 ms |
35164 KB |
Output is correct |
32 |
Correct |
8 ms |
35164 KB |
Output is correct |
33 |
Correct |
7 ms |
35052 KB |
Output is correct |
34 |
Correct |
7 ms |
35164 KB |
Output is correct |
35 |
Correct |
315 ms |
66232 KB |
Output is correct |
36 |
Correct |
309 ms |
64704 KB |
Output is correct |
37 |
Correct |
339 ms |
69460 KB |
Output is correct |
38 |
Correct |
309 ms |
64868 KB |
Output is correct |
39 |
Correct |
353 ms |
63304 KB |
Output is correct |
40 |
Correct |
356 ms |
66876 KB |
Output is correct |
41 |
Correct |
414 ms |
61016 KB |
Output is correct |
42 |
Correct |
144 ms |
46932 KB |
Output is correct |
43 |
Correct |
184 ms |
57604 KB |
Output is correct |
44 |
Correct |
327 ms |
56144 KB |
Output is correct |
45 |
Correct |
382 ms |
67700 KB |
Output is correct |
46 |
Correct |
260 ms |
60916 KB |
Output is correct |
47 |
Correct |
249 ms |
61012 KB |
Output is correct |
48 |
Correct |
373 ms |
69456 KB |
Output is correct |
49 |
Correct |
350 ms |
64712 KB |
Output is correct |
50 |
Correct |
305 ms |
59972 KB |
Output is correct |
51 |
Correct |
385 ms |
72532 KB |
Output is correct |
52 |
Correct |
5 ms |
34908 KB |
Output is correct |
53 |
Correct |
441 ms |
60756 KB |
Output is correct |
54 |
Correct |
441 ms |
54812 KB |
Output is correct |
55 |
Correct |
449 ms |
67784 KB |
Output is correct |
56 |
Correct |
334 ms |
60888 KB |
Output is correct |
57 |
Correct |
363 ms |
56912 KB |
Output is correct |
58 |
Correct |
420 ms |
70908 KB |
Output is correct |
59 |
Incorrect |
391 ms |
72528 KB |
Output isn't correct |
60 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
59988 KB |
Output is correct |
2 |
Correct |
391 ms |
70244 KB |
Output is correct |
3 |
Correct |
374 ms |
66232 KB |
Output is correct |
4 |
Correct |
350 ms |
56664 KB |
Output is correct |
5 |
Correct |
6 ms |
34908 KB |
Output is correct |
6 |
Correct |
378 ms |
62064 KB |
Output is correct |
7 |
Correct |
166 ms |
43604 KB |
Output is correct |
8 |
Correct |
205 ms |
57748 KB |
Output is correct |
9 |
Correct |
399 ms |
67000 KB |
Output is correct |
10 |
Correct |
241 ms |
59984 KB |
Output is correct |
11 |
Correct |
248 ms |
66228 KB |
Output is correct |
12 |
Correct |
5 ms |
34908 KB |
Output is correct |
13 |
Correct |
5 ms |
34908 KB |
Output is correct |
14 |
Correct |
5 ms |
34908 KB |
Output is correct |
15 |
Correct |
5 ms |
34908 KB |
Output is correct |
16 |
Correct |
5 ms |
34908 KB |
Output is correct |
17 |
Correct |
5 ms |
35076 KB |
Output is correct |
18 |
Correct |
5 ms |
34908 KB |
Output is correct |
19 |
Correct |
5 ms |
35056 KB |
Output is correct |
20 |
Correct |
5 ms |
34908 KB |
Output is correct |
21 |
Correct |
5 ms |
34908 KB |
Output is correct |
22 |
Correct |
5 ms |
34908 KB |
Output is correct |
23 |
Correct |
6 ms |
34908 KB |
Output is correct |
24 |
Correct |
5 ms |
34908 KB |
Output is correct |
25 |
Correct |
7 ms |
34908 KB |
Output is correct |
26 |
Correct |
5 ms |
34904 KB |
Output is correct |
27 |
Correct |
5 ms |
35032 KB |
Output is correct |
28 |
Correct |
8 ms |
35160 KB |
Output is correct |
29 |
Correct |
8 ms |
35160 KB |
Output is correct |
30 |
Correct |
8 ms |
35160 KB |
Output is correct |
31 |
Correct |
8 ms |
35164 KB |
Output is correct |
32 |
Correct |
8 ms |
35164 KB |
Output is correct |
33 |
Correct |
7 ms |
35052 KB |
Output is correct |
34 |
Correct |
7 ms |
35164 KB |
Output is correct |
35 |
Correct |
315 ms |
66232 KB |
Output is correct |
36 |
Correct |
309 ms |
64704 KB |
Output is correct |
37 |
Correct |
339 ms |
69460 KB |
Output is correct |
38 |
Correct |
309 ms |
64868 KB |
Output is correct |
39 |
Correct |
353 ms |
63304 KB |
Output is correct |
40 |
Correct |
356 ms |
66876 KB |
Output is correct |
41 |
Correct |
414 ms |
61016 KB |
Output is correct |
42 |
Correct |
144 ms |
46932 KB |
Output is correct |
43 |
Correct |
184 ms |
57604 KB |
Output is correct |
44 |
Correct |
327 ms |
56144 KB |
Output is correct |
45 |
Correct |
382 ms |
67700 KB |
Output is correct |
46 |
Correct |
260 ms |
60916 KB |
Output is correct |
47 |
Correct |
249 ms |
61012 KB |
Output is correct |
48 |
Correct |
373 ms |
69456 KB |
Output is correct |
49 |
Correct |
350 ms |
64712 KB |
Output is correct |
50 |
Correct |
305 ms |
59972 KB |
Output is correct |
51 |
Correct |
385 ms |
72532 KB |
Output is correct |
52 |
Correct |
5 ms |
34908 KB |
Output is correct |
53 |
Correct |
441 ms |
60756 KB |
Output is correct |
54 |
Correct |
441 ms |
54812 KB |
Output is correct |
55 |
Correct |
449 ms |
67784 KB |
Output is correct |
56 |
Correct |
334 ms |
60888 KB |
Output is correct |
57 |
Correct |
2084 ms |
180468 KB |
Output is correct |
58 |
Correct |
1840 ms |
156976 KB |
Output is correct |
59 |
Correct |
1675 ms |
133388 KB |
Output is correct |
60 |
Correct |
2145 ms |
195928 KB |
Output is correct |
61 |
Correct |
2569 ms |
137344 KB |
Output is correct |
62 |
Correct |
2060 ms |
112436 KB |
Output is correct |
63 |
Correct |
2297 ms |
171100 KB |
Output is correct |
64 |
Correct |
1923 ms |
136996 KB |
Output is correct |
65 |
Correct |
363 ms |
56912 KB |
Output is correct |
66 |
Correct |
420 ms |
70908 KB |
Output is correct |
67 |
Incorrect |
391 ms |
72528 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |