Please find the mistake in my code

question link : CodeChef: Practical coding for everyone
solution link : CodeChef: Practical coding for everyone

For
4
1 2 4 3
it gives o/p 4. This is not correct answer. You are only checking for pairs (1,2) , (3,4). But you should also check for (2,3)

But the question says to check for every pair of adjacent Knights.
therefore if i give the input:
4
1 2 4 3
then at least two Knights should get their dessert, so chef will select the dessert of price 1 and 3. So the final price should be 4.

Here pairs are (1,2) (2,3) (3,4) (4,1). In all the 4 pairs condition should be satisfied

this problem is similar to leetCode’s House Robber II.