#Q15. 「一本通 1.2 练习 1」数列分段 II

「一本通 1.2 练习 1」数列分段 II

Description

Given a sequence of positive integers AA of length NN, it is to be divided into MM segments. Each segment must be continuous, and the maximum sum among all segments should be minimized.

For example, consider the sequence 4  2  4  5  14 \ \ 2 \ \ 4 \ \ 5 \ \ 1 to be divided into 33 segments:

If divided as [4[4 2][42][4 5][1]5][1], the sums of the segments are 6,9,16, 9, 1, and the maximum sum is 99;

If divided as [4][2[4][2 4][54][5 1]1], the sums of the segments are 4,6,64, 6, 6, and the maximum sum is 66;

Moreover, no matter how the sequence is divided, the maximum sum cannot be less than 66.

Thus, the minimum possible maximum sum when dividing the sequence 4  2  4  5  14 \ \ 2 \ \ 4 \ \ 5 \ \ 1 into 33 segments is 66.

Input Format

The first line contains two positive integers NN and MM;

The second line contains NN non-negative integers AiA_i separated by spaces, as described in the problem.

Output Format

Output a single positive integer, which is the minimum possible maximum sum among all segments.

Sample 1

5 3
4 2 4 5 1

6

Data Range and Hints

For 20%20\% of the data, N10N \leq 10;

For 40%40\% of the data, N1000N \leq 1000;

For 100%100\% of the data, N105N \leq 10^5, MNM \leq N, and the sum of AiA_i does not exceed 10910^9.