catalystgma's blog

By catalystgma, history, 6 years ago, In English

Hi,

I am trying to solve problem https://mirror.codeforces.com/contest/372/problem/A .

This is my sourcecode: http://cpp.sh/3rqwk. My codeforces submission is here: https://mirror.codeforces.com/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!

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 years ago, # |
  Vote: I like it +1 Vote: I do not like it
  • »
    »
    6 years ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    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.

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 4   Vote: I like it +2 Vote: I do not like it

      Not really, you should do it = ss.erase(it) for since C++11 erase(it) always returns iterator next to it. And no copy is really need.
      P.S. In your case it would be even better if you use multiset sorted by descending.