https://codeforces.com/problemset/problem/313/D Hello everyone. I've solved this problem by dynamic programming, yeah but my teacher after looking at the problem, he said it can be solved by using stack, I'm really "WTF" after what he said, I did ask him how to solve it like that but he explained it and I couldn't understand, so can anyone say whether it is possible to solve it by using stack, I'm kinda curious about that approach ? Thanks a lot.