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

#BS0000360. Đóng hộp chuông bò (More Cowbell)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đóng hộp chuông bò (More Cowbell)

More Cowbell

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Kevin Sun is moving his collection of nn cowbells from Naperthrill to Exeter. For safe transportation he has kk boxes, each of the same capacity ss.

Cowbell ii has size sis_i, and the collection is already ordered by nondecreasing size. A box holds at most two cowbells. One or two cowbells fit in a box exactly when their combined size is at most ss. Boxes may be left unused.

Find the smallest capacity that allows all nn cowbells to be packed using at most kk boxes.

Input

The first line contains integers n,kn,k, the numbers of cowbells and boxes.

The second line contains the nn integer sizes s1,s2,…,sns_1,s_2,\ldots,s_n in nondecreasing order.

Output

Print one integer: the minimum box capacity.

Subtasks

  • Subtask 1 (20 points): 1≤n≤2k≤121\le n\le 2k\le 12; 1≤s1≤s2≤⋯≤sn≤1061\le s_1\le s_2\le\cdots\le s_n\le 10^6.
  • Subtask 2 (30 points): 1≤n≤2k≤20001\le n\le 2k\le 2000; 1≤s1≤s2≤⋯≤sn≤1061\le s_1\le s_2\le\cdots\le s_n\le 10^6.
  • Subtask 3 (50 points): 1≤n≤2k≤1000001\le n\le 2k\le 100000; 1≤s1≤s2≤⋯≤sn≤1061\le s_1\le s_2\le\cdots\le s_n\le 10^6.

Examples

Input 1

2 1
2 5

Output 1

7

Explanation 1

There is one box for both cowbells. Their combined size is 2+5=7, so any smaller capacity is insufficient.

Input 2

4 3
2 3 5 9

Output 2

9

Explanation 2

Pack sizes 2 and 3 together, and sizes 5 and 9 separately. Capacity 9 suffices for three boxes. No box smaller than 9 can contain the largest cowbell.

Input 3

3 2
3 5 7

Output 3

8

Explanation 3

At least one pair must share a box. The two smallest sizes sum to 3+5=8, so any pair requires capacity at least 8. Pair them and leave size 7 alone to attain 8.