LC 3013 - Divide an Array Into Subarrays With Minimum Cost II

Approach Given a solution [ group A ] [i1 .. ] .. [ .. ] [i(k-1)], the distance between i1 and i(k-1)should be smaller then dist, and we assume that now the group A is fixed. The problem now is that we need to findk-2minimum elements in the range[i1 .. i(k-1)](excludingi1` itself), this part is similar to previous daily. Now we tried to do a sliding window, and we the current score is the first element of group A, plus the first element within the sliding window (dist+1 wide), and the sum of k-2 minimum value inside that sliding window (exlude the first one). We maintain the best score and we get the answer after sliding window. ...

February 2, 2026 · 2 min