Array
3505. Minimum Operations to Make Elements Within K Subarrays Equal
The two halves of this problem never talk to each other, and seeing that is most of the work. The cost of flattening one fixed block of x elements is the sum of distances from those elements to their median — k plays no part in it. Deciding which blocks to buy is then a one-dimensional scheduling question over n-x+1 precomputed numbers, where the original values play no part. So: price every window once, then run a DP over the prices.
Loading…