Help with FROGV

https://www.codechef.com/viewsolution/15972100 This is my new attempt at FROGV. https://www.codechef.com/problems/FROGV. Still getting a WA.Can anybody tell me where i’m making the mistake? Thanks.

I think you are making a logical error in your cmp method.

Your code:

return (l[0] < r[0]) ? -1
:      ((r[0] > l[0]) ? 1
:      (l[1] < r[1] ? -1
:      ((r[1] < l[1] ? 1:0))));

Correct code:

return (l[0] < r[0]) ? -1
:      ((r[0] > l[0]) ? 1
:      (l[1] < r[1] ? 1
:      ((r[1] < l[1] ? -1:0))));

I would suggest using std::sort() if you are using c++.
Also you can use an array of pair< int, int > or vector of pair < int, int > instead of using a 2D array.
That way, writing a compare function for std::sort() will be much less complicated.

Hope this helps!

Here is your accepted code: https://www.codechef.com/viewsolution/15972213

my method sorts 0 3 8 5 12 as: 0 3 5 8 12.
The correct method sorts it as:3 5 8 12 0. This is breaking the ascending order yet it gets AC.Can you please explain how?

The AC code sorts 0 3 8 5 12 as 0 3 5 8 12 only!
Your code sorts 0 3 8 5 12 as 0 3 8 5 12. In fact your code does not sorts the arr at all.
Please check carefully.