Editorial for Google Kickstart Round-A Problem-B

What is the best way to approach this question? I have seen solutions of this question, where most of the people are using dynamic programming approach. Please provide a detailed editorial of this question. Thank you in advance!!

No one to help here?!!!