Wrong Answer for TWODOGS

This is my code for [TWODOGS][1] in this February Long Challenge.


For number of inputs I tried, I am getting correct answer but on submitting I get WA. Please help for which cases this code doesn't work.

  [1]: http://www.codechef.com/FEB14/problems/TWODOGS
  [2]: http://www.codechef.com/viewsolution/3435634

If you read the problem carefully, it says:

alt text

I think that should be enough for you to realise where you went wrong.

Test case:

5 4

2 1 6 5 2

Answer: -1 ;
Your output: 1

1 Like

Still getting wrong answer… http://www.codechef.com/viewsolution/3446568

Try this test case:
5 4
2 3 5 1 2

It’s quite difficult to point out the bug in your program! Still try this test case

Test Case:
5 4
1 3 3 2 1
Your O/P: 3
Actual O/P: 2

Maybe you are not checking the time for all required combinations in the array! You are missing the combination of 1 on first position and 3 on second position. You only calculated the time of 1 on first position and 3 on third position.