Ulla Britta and Sticks help

i have tried this problem , select 3 consecutive points and try to make them valid till end
but this greedy approach is wrong answer what could be the best approach to solve this?
problem : CodeChef: Practical coding for everyone
my sol : CodeChef: Practical coding for everyone (WA)

use dp

I did it using dp. The values were too small and values can be only up to the maximum in the array.The states were current index and past two values.CodeChef: Practical coding for everyone

if you don’t mind could you explain your solution with commenting your code?