AmazonOA #279
Maximum Quality Sum
估计中等可在线判题
Every packet must be assigned to one of exactly channels non-empty channels. You may group them arbitrarily; a group does not need to be contiguous in the original order. The quality of a channel is the median of its packet sizes; with an even count, take the average of the two middle items. Maximize the total quality, then round it up to an integer once at the end.
输入格式
The first line contains n channels and the second line contains packets. 1≤n≤500000, 1≤packets[i]≤10^9, 1≤channels≤n.
输出格式
Output a single integer, the answer.
样例 1
输入:
5 2
1 2 3 4 5
输出:
8
样例 2
输入:
5 2
2 2 1 5 3
输出:
7
样例 3
输入:
3 3
89 48 14
输出:
151
样例说明
The answers are 8, 7 and 151 respectively. In the first example 5 is on its own, and the remaining 1,2,3,4 have median 2.5, so the total 7.5 rounds up to 8.