#include<iostream>
#include<cstdlib>
#include<vector>
#include<cassert>
#include<set>
#define ll long long
using namespace std;
ll q,l,a,b,c,d;
set<pair<int,ll>> A,C;
int main(){
ios_base::sync_with_stdio(0);
cin>>q>>l;
for(int i=0;i<q;i++){
cin>>a>>b>>c;
if(a==1) A.insert({b+l,c}); else C.insert({b,c});
set<pair<int,ll>>::iterator it1=A.begin(),it2=C.begin();
ll wyn=0;
d=it2->second;
c=it1->second;
while(true){
if(it1==A.end()) break;
while(it2!=C.end() && it2->first+2*l<it1->first){
it2++;
d=it2->second;
}
if(it2==C.end()) break;
//d=it2->second;
while(it2!=C.end() && c && it2->first<=it1->first){
if(d>c){
d-=c;
wyn+=c;
break;
}
c-=d;
wyn+=d;
it2++;
d=it2->second;
}
it1++;
if(it1==A.end()) break;
c=it1->second;
}
cout<<wyn<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
17 ms |
460 KB |
Output is correct |
7 |
Correct |
13 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
35 ms |
468 KB |
Output is correct |
11 |
Correct |
37 ms |
592 KB |
Output is correct |
12 |
Correct |
37 ms |
588 KB |
Output is correct |
13 |
Correct |
38 ms |
540 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
25 ms |
544 KB |
Output is correct |
16 |
Correct |
32 ms |
568 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
35 ms |
552 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
38 ms |
552 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
51 ms |
500 KB |
Output is correct |
24 |
Correct |
5 ms |
544 KB |
Output is correct |
25 |
Correct |
53 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Execution timed out |
4046 ms |
2396 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4073 ms |
10304 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
324 KB |
Output is correct |
6 |
Correct |
17 ms |
460 KB |
Output is correct |
7 |
Correct |
13 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
396 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
35 ms |
468 KB |
Output is correct |
11 |
Correct |
37 ms |
592 KB |
Output is correct |
12 |
Correct |
37 ms |
588 KB |
Output is correct |
13 |
Correct |
38 ms |
540 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
25 ms |
544 KB |
Output is correct |
16 |
Correct |
32 ms |
568 KB |
Output is correct |
17 |
Correct |
5 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
35 ms |
552 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
38 ms |
552 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
51 ms |
500 KB |
Output is correct |
24 |
Correct |
5 ms |
544 KB |
Output is correct |
25 |
Correct |
53 ms |
480 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Execution timed out |
4046 ms |
2396 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |