Calvins Game(INOI) , what am I missing?

I am first running dp from k to last and finding what is the maximum sum which can be obtained an d th eposition where the maximum sum is obtained and from that position I am running a dp in backward direction till i=0; I am getting 11/17 test cases passed,don’t know what is going wrong . Please help!! INOI is 3 days away.
Problem-: https://www.codechef.com/IOIPRAC/problems/INOI1301

Solution-: https://www.codechef.com/viewsolution/12402219

Read the problem statement carefully.

You have forgotten about a case where there might be negative outcomes. That’s it I guess.

//