Problem link: https://www.codechef.com/PROC2018/problems/PROC18D

What should be the approach this question? Can’t we use stack in this?

I am not able to understand DP used in submitted solutions,how can we use DP in this question.

What should be the approach this question? Can’t we use stack in this?

I am not able to understand DP used in submitted solutions,how can we use DP in this question.