WA in ACPC10D

guys i am getting repeatedly WA in this question link text

my code link link text

i tried approximately every test case on spoj toolkit…
please help me out

First of all you are using the array arr[n+1][4] but accessing dp[i-1][j+1] where j can be 3, which means the index j+1 is out-of-bounds. Luckily, in this case that ends up accessing the first cell of the next row, which is MAX and the programs works as intended, but you should not be relying on anything that is undefined behavior.

Now coming to the logical error, you just overlooked a possible path that goes a[1][2] -> a[1][3] -> ... -> a[n][2] :smiley:

thanks for helping me out :slight_smile:

//