Approach hintTry it first, then revealHide
A segment is c-good when one half consists only of c and the other half is (c + 1)-good. Recurse on both options, counting the changes needed to fill one half with c, and keep the cheaper one. O(n log n).