Problem 3523 · Medium
Merge neighbouring segments into their maxima with a stack, so the segment maxima never decrease.
Open the interactive visualisation