← 返回 salesforce 的题目列表Minimum Sum of Weekly Campaign Maxima
类型:online_judge
Problem: Minimize the Sum of Weekly Campaign Maxima
You are given an integer array costs of length n, where costs[i] is the cost of the i-th campaign. You are also given an integer weeks, representing the total number of weeks.
You need to split all campaigns, in their original order, into exactly weeks non-empty contiguous groups. Each group represents the campaigns scheduled in one week. The cost of a week is defined as the maximum campaign cost within that week.
Return the minimum possible sum of weekly costs.
If it is impossible to split the campaigns, for example when weeks > n, return -1.
Input Format
n weeks
costs[0] costs[1] ... costs[n-1]
Output Format
minimum_sum
Constraints
1 <= n <= 300
1 <= weeks <= 300
1 <= costs[i] <= 100000
Example
Input:
8 3
2 5 4 3 7 1 6 8
One optimal partition is:
[2, 5, 4, 3] | [7, 1, 6] | [8]
The sum of weekly maxima is:
5 + 7 + 8 = 20
Output:
20
Example
Input
8 3
2 5 4 3 7 1 6 8
Output
20