3013. Divide an Array Into Subarrays With Minimum Cost II
You are given a 0-indexed array of integers
nums
of lengthn
, and two positive integersk
anddist
.The cost of an array is the value of its first element. For example, the cost of
[1,2,3]
is1
while the cost of[3,4,1]
is3
.You need to divide
nums
intok
disjoint contiguous subarrays, such that the difference between the starting index of the second subarray and the starting index of thekth
subarray should be less than or equal todist
. In other words, if you dividenums
into the subarraysnums[0..(i1 - 1)], nums[i1..(i2 - 1)], ..., nums[ik-1..(n - 1)]
, thenik-1 - i1 <= dist
.Return the minimum possible sum of the cost of these subarrays.
c++
1 |
|