Submission #890720

#TimeUsernameProblemLanguageResultExecution timeMemory
890720Ahmed57Ants and Sugar (JOI22_sugar)C++17
0 / 100
1 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(0);cin.tie(0); //freopen("input.txt","r",stdin); //freopen("outout.txt","w",stdout); int n,m; cin>>n>>m; multiset<array<int,3>> s; for(int i = 1;i<=n;i++){ int t,x,a; cin>>t>>x>>a; s.insert({x,t,a});multiset<pair<int,int>> sugar,ants; long long all = 0; for(auto i:s){ int rem = i[2]; if(i[1]==2){ while(!ants.empty()&&abs((-(*ants.begin()).first)-i[2])<=m&&rem){ int pos = (*ants.begin()).first; int sec = (*ants.begin()).second; int e = min(sec,rem); rem-=e;sec-=e; all+=e; if(sec!=0){ ants.insert({pos,sec}); } } if(rem)sugar.insert({-i[0],rem}); }else{ while(!sugar.empty()&&abs((-(*sugar.begin()).first)-i[2])<=m&&rem){ int pos = (*sugar.begin()).first; int sec = (*sugar.begin()).second; int e = min(sec,rem); rem-=e;sec-=e; all+=e; if(sec!=0){ sugar.insert({pos,sec}); } } if(rem)ants.insert({-i[0],rem}); } } cout<<all<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...