#d2954. 分段求和
分段求和
Splitting Sum
Problem Description
You are given a positive integer sequence of length . Split it into () contiguous segments so that each segment is consecutive, and the maximum of the segment sums is minimized.
What "maximum minimized" means:
For example, to split the sequence into segments:
- Split as : the segment sums are , , ; the maximum is .
- Split as : the segment sums are , , ; the maximum is .
No matter how you split it, the maximum cannot be smaller than .
So for the sequence split into segments, the minimum possible value of the maximum segment sum is .
Input Format
The first line contains two positive integers and .
The second line contains space-separated non-negative integers , as described above.
Output Format
Output one positive integer: the minimized maximum segment sum.
Sample Input
5 3
4 2 4 5 1
Sample Output
6
Constraints
.