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

#BS0000256. Đóng đồ vào thùng lớn (Big Boxes)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đóng đồ vào thùng lớn (Big Boxes)

Big Boxes

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Brandon Greg Jr. is moving to the United States. His nn items are in a fixed order; item ii weighs aia_i. Pack them into exactly kk nonempty consecutive groups, one per box. Ignore the empty boxes’ weight. Minimize the heaviest loaded box.

Input

The first line contains integers n,kn,k, the item and box counts. The second contains the nn integer weights aia_i in order.

Output

Print the minimum possible weight of the heaviest box.

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≤1051\le k\le n\le 10^5; 1≤ai≤1041\le a_i\le 10^4 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≤1051\le k\le n\le 10^5; 1≤ai≤1041\le a_i\le 10^4 for all 1≤i≤n1\le i\le n.

Examples

Input

7 2
3 1 1 3 9 5 2

Output

16

Explanation

Cut after item 4: the weights are 8 and 16. At capacity 15 the first box cannot include item 5 because the prefix weighs 17. The remaining items weigh at least 16, so 16 is optimal.