AmazonOA #17
Get Minimum Pen Drive Size
估计中等可在线判题
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.
输入格式
The first line contains n k (1≤k≤n≤200000 and n≤2k); the second line contains the n game sizes (1..10⁹).
输出格式
Output a single integer, the answer required by the problem.
样例 1
输入:
4 3
9 2 4 6
输出:
9
样例 2
输入:
2 1
1 2
输出:
3
样例 3
输入:
1 1
4
输出:
4
样例说明
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.