Dp problem help

someone plz help me in the problem …i have been trying for days but now when i saw the editorial i was not able to understand the solution … someone plz help me out …by giving solution explanation in this problem …