#P1182. 数列分段 Section II

数列分段 Section II

Description

Given a sequence of positive integers A1NA_{1\sim N} of length NN, you need to partition it into MM (MNM \leq N) contiguous segments, such that the maximum segment sum is minimized.

About minimizing the maximum:

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

Partition it as:

[4 2][4 5][1][4\ 2][4\ 5][1]

The sum of the first segment is 66, the sum of the second segment is 99, the sum of the third segment is 11, and the maximum of these sums is 99.

Partition it as:

[4][2 4][5 1][4][2\ 4][5\ 1]

The sum of the first segment is 44, the sum of the second segment is 66, the sum of the third segment is 66, and the maximum of these sums is 66.

Moreover, no matter how you partition it, the maximum will not be smaller than 66.

Therefore, for the sequence 4 2 4 5 14\ 2\ 4\ 5\ 1 divided into 33 segments, the minimum possible maximum segment sum is 66.

Input Format

The first line contains two positive integers N,MN, M.

The second line contains NN space-separated non-negative integers AiA_i, as described above.

Output Format

A single positive integer: the minimum possible value of the maximum segment sum.

5 3
4 2 4 5 1
6

Hint

Constraints:

  • For 20%20\% of the testdata, N10N \leq 10.
  • For 40%40\% of the testdata, N1000N \leq 1000.
  • For 100%100\% of the testdata, 1N1051 \leq N \leq 10^5, MNM \leq N, Ai<108A_i < 10^8, and the answer does not exceed 10910^9.

Translated by ChatGPT 5