Codeforces#317Div.2 B - Order Book
問題文はこちら: Problem - B - Codeforces
レートが減少してついに緑に戻ってきてしまった。問題文を理解できず2WAが結構痛い。
orderをまとめるのも降順に取り出すのもmapを使えばできる。iteratorが若干めんどくさいだけでそこを気をつければできるはず。
今回からソースコードをのせるようにしてみた。参考になれば幸いである。
map<int,ll> buy; map<int,ll> sell; int cnt; int main(){ int n,s;cin>>n>>s; char d;int p,q; REP(i,n){ cin>>d>>p>>q; if(d=='B') buy[p]+=q; if(d=='S') sell[p]+=q; } int sn=min(s,(int)sell.size()); int bn=min(s,(int)buy.size()); for(auto it=sell.rbegin();it!=sell.rend();it++){ if(cnt++>=sell.size()-sn) cout<<"S "<<it->first<<" "<<it->second<<endl; } cnt=0; for(auto it=buy.rbegin();it!=buy.rend();it++){ if(cnt++<bn) cout<<"B "<<it->first<<" "<<it->second<<endl; } }
問題文がわかりにくかったしEIGO力が欲しい。