Problem link: CodeChef: Practical coding for everyone

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.