Hi,
I am trying to solve problem https://codeforces.me/contest/372/problem/A .
This is my sourcecode: http://cpp.sh/3rqwk. My codeforces submission is here: https://codeforces.me/contest/372/submission/55705312.
My code runs on my computer and cpp.sh on the two examples successfully but gets "Runtime Error" with a huge descrpition on the site. I know how volatile the are multiset erase operations, but I can't figure out why it won't run specifically on codeforces.
Thank you!
https://stackoverflow.com/questions/2874441/deleting-elements-from-stl-set-while-iterating
Thanks, it helped. It seems that you have to copy the incremented iterator before attempting to erase. Weird how it works on some compilers without copying.
Not really, you should do
it = ss.erase(it)
for since C++11erase(it)
always returns iterator next toit
. And no copy is really need.P.S. In your case it would be even better if you use multiset sorted by descending.