This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |