289 传统题

[ABC319D] 最小换行窗宽 (Minimum Width)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
3

[ABC319D] 最小换行窗宽 (Minimum Width)

Problem Statement

Takahashi is displaying a sentence with NN words in a window. All words have the same height, and the width of the ii-th word (1≤i≤N)(1\leq i\leq N) is LiL _ i.

The words are displayed in the window separated by a space of width 11. More precisely, when the sentence is displayed in a window of width WW, the following conditions are satisfied.

  • The sentence is divided into several lines.

  • The first word is displayed at the beginning of the top line.

  • The ii-th word (2≤i≤N)(2\leq i\leq N) is displayed either with a gap of 11 after the (i−1)(i-1)-th word, or at the beginning of the line below the line containing the (i−1)(i-1)-th word. It will not be displayed anywhere else.

  • The width of each line does not exceed WW. Here, the width of a line refers to the distance from the left end of the leftmost word to the right end of the rightmost word.

When Takahashi displayed the sentence in the window, the sentence fit into MM or fewer lines. Find the minimum possible width of the window.

Input

The input is given from Standard Input in the following format:

$N$ $M$
$L _ 1$ $L _ 2$ $\ldots$ $L _ N$

Output

Print the answer in one line.

Example

13 3
9 5 2 7 1 8 8 2 1 5 2 3 6
26

Note

  • Constraints:

  • 1≤M≤N≤2×1051\leq M\leq N\leq2\times10 ^ 5

  • 1≤Li≤109 (1≤i≤N)1\leq L _ i\leq10^9\ (1\leq i\leq N)

  • All input values are integers.

  • Source: ABC319D