CHEFADD Help

I have tried to solve this problem, but during the contest did not get any ideas. After the contest I saw that people used DP. But I have no clue how this is a DP problem. Can someone please explain the thought process behind this problem.
CHEFADD

1 Like