#d2954. 分段求和

分段求和

Splitting Sum

Problem Description

You are given a positive integer sequence A1…NA_{1\dots N} of length NN. Split it into MM (M≤NM \le N) 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 4,2,4,5,14, 2, 4, 5, 1 into 33 segments:

  • Split as [4,2][4,5][1][4, 2][4, 5][1]: the segment sums are 66, 99, 11; the maximum is 99.
  • Split as [4][2,4][5,1][4][2, 4][5, 1]: the segment sums are 44, 66, 66; the maximum is 66.

No matter how you split it, the maximum cannot be smaller than 66.

So for the sequence 4,2,4,5,14, 2, 4, 5, 1 split into 33 segments, the minimum possible value of the maximum segment sum is 66.

Input Format

The first line contains two positive integers NN and MM.

The second line contains NN space-separated non-negative integers AiA_i, 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

1≤N≤105, M≤N, Ai≤1081 \le N \le 10^5,\ M \le N,\ A_i \le 10^8.