#FT0000055. Chia dãy thành các đoạn với chi phí nhỏ nhất II (Divide an Array Into Subarrays With Minimum Cost II)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia dãy thành các đoạn với chi phí nhỏ nhất II (Divide an Array Into Subarrays With Minimum Cost II)
Divide an Array Into Subarrays With Minimum Cost II
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Partition the array of length into exactly nonempty, disjoint, consecutive subarrays that cover the entire array in order. The cost of a subarray equals its first element; the total cost is the sum of all first elements.
Let and denote the zero-based starting positions of the second and -th subarrays. The partition is valid only when . Find the minimum total cost over all valid partitions.
Input
- Line 1: integers for array length, number of partitions and maximum difference between the specified starts.
- Line 2: exactly integers .
Output
Print exactly one integer: the minimum total cost of a valid partition.
Subtasks
Subtask 1 (20 points):
- ; ; ; for every .
Subtask 2 (30 points):
- ; ; ; for every .
Subtask 3 (50 points):
- ; ; ; for every .
Examples
Examples 1
Input
6 3 3
1 3 2 6 4 2
Output
5
Explanation
Choose , , and . Their starts are and . Their costs are , yielding total 5, which is minimal for the given sequence.
Examples 2
Input
4 3 1
10 8 18 9
Output
36
Explanation
The last two subarrays must start at adjacent positions because . Starting at indices 1 and 2 costs , whereas starting at 2 and 3 costs . Thus the answer is 36.