The compare function is not necessary,By default pairs get sorted by first element.
1 Like
bro both of my test cases passed after i replaced sort with stable_sort, and also i donāt think long long is the problem here contraints were under 10^9 and only arithmetic operation used here is divisionā¦actually i canāt believe your code passed and mine didānt they are exactly the sameā¦i guess i got unlucky then
you are right the problem was with the sort function
I copied your code and spammed some submissions.
So, here is what i found out
The problem is not with sort()
but is with you func(). It gives the incorrect output, but instead if you replace
sort(pos.begin(),pos.end(),func);
with sort(pos.begin(),pos.end());
, it will work.
YES, it was your func that messed it up and not sort()