By Cadis_Etrama_Di_Raizel, history, 4 months ago,

Hi, codeforces, Getting straight to the point my submission 143634261 failed at system testing and gave me a runtime error at test case 14. I tried searching about it but the only useful resource I was able to find is this blog but my code can't go beyond the limit and can't go negative. So, please help me.

• -8

 » 4 months ago, # |   0 Your comparator is fishy:bool cmp(pair a,pair b){ if(a.first==b.first){ return a.second>b.first; } return a.first
•  » » 4 months ago, # ^ | ← Rev. 2 →   0 Thanks for helping.Just a doubt: Shouldn't this will only cause a and b to switch their position whenever they are compared. It should not throw an error for this (speaking from my knowledge about the sort function).Edit: I checked by removing it and the code worked but I still don't get why it is throwing that error.
•  » » » 4 months ago, # ^ |   +5 Having a bad comparator is undefined behaviour, so it may fail in various ways depending on the sort function implementation. See https://codeforces.com/blog/entry/72525 and https://stackoverflow.com/questions/45929474/why-must-stdsort-compare-function-return-false-when-arguments-are-equalIt's a rather common pitfall. Even though in some cases people get an AC verdict despite a broken comparator and don't have any reason to learn anything.
•  » » » » 4 months ago, # ^ |   0 Thanks a lot for helping out. I bless positive delta on you.
•  » » » 4 months ago, # ^ | ← Rev. 2 →   0 the comparator must follow these 3 rules: 1. For all x, comp(x,x) is false. 2. For all x and y, if comp(x,y) is true, comp(y,x) is false. 3. For all x, y, and z, if comp(x,y) and comp(y,z) are both true, comp(x,z) must be true.
 » 4 months ago, # |   0 Same happened with 143518267 this submission. because on a string i used s[n] th character. here n is the size of string.
•  » » 4 months ago, # ^ |   0 I don't think that's the problem with my code as never go out of bound. The real problem was mentioned in the above comment. Check it if you are interested.