Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Divide Array Into Subarrays

Try to solve the Minimum Cost to Divide Array Into Subarrays problem.

Statement

You are given two integer arrays nums and cost of equal length, and an integer k.

You need to partition the array nums into one or more non-empty contiguous subarrays.

Suppose the array is divided into mm subarrays. For the jthj^{\text{th}} subarray (where 1≤j≤m1 \leq j \leq m) ending at index iji_j and starting after the end of the previous subarray:
The cost of this jthj^{\text{th}} subarray is calculated as:
(∑t=0ijnums[t]+k×j)×(sum of cost in the jth subarray)\left(\sum_{t=0}^{i_j} \text{nums}[t] + k \times j\right) \times \left(\text{sum of cost in the } j^{\text{th}} \text{ subarray}\right)

Return the minimum total cost to divide the array into subarrays.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • cost.length ==== nums.length

  • 1≤1 \leq nums[i], cost[i] ≤1000\leq 1000

  • 1≤1 \leq k ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Divide Array Into Subarrays

Try to solve the Minimum Cost to Divide Array Into Subarrays problem.

Statement

You are given two integer arrays nums and cost of equal length, and an integer k.

You need to partition the array nums into one or more non-empty contiguous subarrays.

Suppose the array is divided into mm subarrays. For the jthj^{\text{th}} subarray (where 1≤j≤m1 \leq j \leq m) ending at index iji_j and starting after the end of the previous subarray:
The cost of this jthj^{\text{th}} subarray is calculated as:
(∑t=0ijnums[t]+k×j)×(sum of cost in the jth subarray)\left(\sum_{t=0}^{i_j} \text{nums}[t] + k \times j\right) \times \left(\text{sum of cost in the } j^{\text{th}} \text{ subarray}\right)

Return the minimum total cost to divide the array into subarrays.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • cost.length ==== nums.length

  • 1≤1 \leq nums[i], cost[i] ≤1000\leq 1000

  • 1≤1 \leq k ≤1000\leq 1000