#BS0000360. Đóng hộp chuông bò (More Cowbell)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đó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 cowbells from Naperthrill to Exeter. For safe transportation he has boxes, each of the same capacity .
Cowbell has size , 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 . Boxes may be left unused.
Find the smallest capacity that allows all cowbells to be packed using at most boxes.
Input
The first line contains integers , the numbers of cowbells and boxes.
The second line contains the integer sizes in nondecreasing order.
Output
Print one integer: the minimum box capacity.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
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.