Doubt in csacademy dp problem

Problem link - https://csacademy.com/contest/fii-code-2019-round-3/task/array-macao/statement/

I am not able to understand the state transitions in the above problem.
I tried to understand it through this code - https://csacademy.com/submission/2179933/

but still not clear.