Doubt on problem code->CR196

problem link->CodeChef: Practical coding for everyone
Can anyone tell his approach,that how i apply dp on this question.
I mean tell yor logic behind it.I tried to understand other’s solution but i couldn’t.
Thanks in advance.

The editorial has already been posted :slight_smile:
https://discuss.codechef.com/questions/146285/cr196-editorial