Help in solving SPOJ's Adacoins

Can someone help me to understanding and solving this dynamic programming question , I am completely stuck