Here's the breakthrough: if and , you never need as a candidate for minimum. Why? Because gives a better(or equal) value AND stays valid longer in the sliding window. When expires, is still there with a better(or equal) answer.
This means you can discard candidates that will never be optimal. You only keep the ones that might matter. The monotonic queue does this automatically by removing dominated elements.