Submission #1019886

#TimeUsernameProblemLanguageResultExecution timeMemory
1019886UnforgettableplAnts and Sugar (JOI22_sugar)C++17
6 / 100
4089 ms1396 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...