cswork / OAOpen practice workspace

AmazonOA #17

Get Minimum Pen Drive Size

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyTwo Pointers

Distribute all n games among k children; each child must receive 1 or 2 games. Every child uses a USB drive of the same capacity. Find the minimum capacity.

Input

The first line contains n k (1≤k≤n≤200000 and n≤2k); the second line contains the n game sizes (1..10⁹).

Output

Output a single integer, the answer required by the problem.

Example 1

Input:

4 3
9 2 4 6

Output:

9

Example 2

Input:

2 1
1 2

Output:

3

Example 3

Input:

1 1
4

Output:

4

Example notes

Example 1: put 2 and 4 together and hand out 6 and 9 individually; the three USB drives hold 6, 6 and 9, so capacity 9 is enough, and it cannot be smaller than the size of game 9. Example 2: there is only one child, who must take both games, total size 3. Example 3: one game of size 4, so the capacity is 4.

Editorial

Loading solution…