Help with FROGV

CodeChef: Practical coding for everyone This is my new attempt at FROGV. FROGV Problem - CodeChef. 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: CodeChef: Practical coding for everyone

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.

Can you tell me what iam missing here, iam getting WA, Thanks in Advance.
https://www.codechef.com/viewsolution/34497086

The first thing that I thought of was a range max query on the distances between the two frogs. I’ve used Sparse Table as my RMQ DS. However, I’m getting a fatal runtime error! Can you spot the bug?

My Submission