cswork / OAOpen practice workspace

AmazonOA #309

Minimum Weekly Input (Planning Campaingns :)

Estimated HardJudge-ready

Topics (AI-labelled)Scheduling DP

Split all activities, in their original order, into exactly weeks non-empty contiguous groups, each scheduled in its own week; the effort of a week equals the maximum effort of the activities in its group. Find the minimum total effort over all weeks.

Input

The first line contains n weeks and the second line contains the effort array. The original bounds are 1≤n≤300, 1≤weeks≤n, 1≤cost[i]≤100000.

Output

Output a single integer, the answer.

Example 1

Input:

5 3
1000 500 2000 8000 1500

Output:

9500

Example 2

Input:

3 3
1 2 3

Output:

6

Example 3

Input:

3 1
5 1 4

Output:

5

Example notes

The answers are 9500, 6 and 5. The number of weeks must be exactly as given; no week can be empty, and activities cannot be reordered.

Editorial

Loading solution…