Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Fume's blog

By Fume, history, 2 months ago, In English

Can anyone help me indentifying why my code is giving runtime error for this following code in Problem G: (https://codeforces.com/contest/1971/submission/260600724)

Edit: Got the issue and got AC but could not understand the reason

  • Vote: I like it
  • -3
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

in sort, you should use return a<b;, but not return a<=b, which give RTE or TLE or MLE or somethingelse except AC.

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Oh Nice, it got accepted. But why "return a <= b" gave the RTE error ?

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      https://en.cppreference.com/w/cpp/algorithm/sort

      comparison function object (i.e. an object that satisfies the requirements of Compare) which returns ​true if the first argument is less than (i.e. is ordered before) the second.

      Just because the standard says so. There is no guarantee what will happen if you return less or equal.

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh thanks. Went through the link provided. Still cannot figure out the exact reason for the runtime error. But still, thanks for helping.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Fume (previous revision, new revision, compare).