PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000257. Chiều rộng nhỏ nhất (Minimum Width)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chiều rộng nhỏ nhất (Minimum Width)

Minimum Width

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Takahashi displays nn words in order; word ii has width aia_i. Words cannot be split. Each line starts at the left edge; neighboring words on a line have a gap of width 1. Find the smallest integer window width fitting the sentence in at most kk lines.

Input

The first line contains integers n,kn,k, the word count and line limit. The second contains the nn integer word widths aia_i.

Output

Print the minimum integer width.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤121\le k\le n\le 12; 1≤ai≤501\le a_i\le 50 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤k≤n≤2⋅1051\le k\le n\le 2\cdot10^5; 1≤ai≤1091\le a_i\le 10^9 for all 1≤i≤n1\le i\le n. a1=a2=⋯=ana_1=a_2=\cdots=a_n.
  • Subtask 3 (50 points): 1≤k≤n≤2⋅1051\le k\le n\le 2\cdot10^5; 1≤ai≤1091\le a_i\le 10^9 for all 1≤i≤n1\le i\le n.

Examples

Input

5 2
2 3 4 1 2

Output

9

Explanation

The first two words need width 6 and the last three need 9. At width 8 the first line cannot include word 3 (the first three require 11), leaving words requiring at least 9. Thus 9 is optimal.