Doubt on problem code->CR196

,

problem link->https://www.codechef.com/CORD2019/problems/CR196
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