Codechef laddu questio no-9 of DSA learning series

can anyone just give me the idea how to think of this question and tell me how should i approach to this kind of question.CodeChef: Practical coding for everyone

Isn’t it all about very basic if-else statements, how is this dynamic programming ?