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 <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q,l;
cin >> q >> l;
vector<tuple<int,bool,int>> elements; // Sugar is false
auto solve = [&](){
int ans = 0;
queue<pair<int,int>> sugars;
sort(elements.begin(),elements.end());
for(auto[idx,type,amt]:elements){
if(type==false){sugars.emplace(idx,amt);continue;}
while(!sugars.empty() and sugars.front().first<idx-2*l)sugars.pop();
while(!sugars.empty()){
if(amt>=sugars.front().second){
amt-=sugars.front().second;
ans+=sugars.front().second;
sugars.pop();
} else {
ans+=amt;
sugars.front().second-=amt;
break;
}
}
}
return ans;
};
for(int i=1;i<=q;i++){
int type,x,a;cin>>type>>x>>a;
if(type==1){
elements.emplace_back(x+l,true,a);
} else {
elements.emplace_back(x,false,a);
}
cout << solve() << '\n';
}
}
# | 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... |