LinkedInOA #8
Split Array Largest Sum
Estimated HardJudge-ready
Topics (AI-labelled)Scheduling DPDP Basics
Partition the array, preserving order, into exactly K non-empty contiguous segments, minimizing the sum of the segment maximums; this is not minimizing the maximum segment sum.
Input
The first line contains n K, and the second line contains n numbers. The original bounds are 1<K≤n<300 and 1<a[i]<10^5, yet the original example contains 1; to accommodate that example, this site uses 2≤K≤n≤299 and 1≤a[i]≤99999, keeping the entire original strict domain.
Output
Output a single integer answer.
Example 1
Input:
5 2
1 5 3 4 2
Output:
6
Example 2
Input:
3 3
2 2 2
Output:
6
Example 3
Input:
3 2
9 1 2
Output:
11
Example notes
The outputs of the three public examples are, in order: 6; 6; 11. Checked by independent enumeration or direct simulation.
Editorial
Loading solution…