cswork / OA打开练习工作台

AmazonOA #105

Channels Max Quality

估计中等可在线判题

考点(AI 标注)贪心调度原地数组

Divide all packets into exactly k non-empty channels, using each packet once. A channel's quality is its median, where an even count takes the average of the two middle numbers; maximize the total quality and round it to an integer (0.5 rounds up).

输入格式

The first line contains n k (1≤k≤n≤100000); the second line contains n packet values (1..10⁹).

输出格式

Output a single integer answer.

样例 1

输入:

5 2
1 2 3 4 5

输出:

8

样例 2

输入:

6 2
5 2 2 1 5 3

输出:

7

样例 3

输入:

2 2
1 2

输出:

3

样例说明

Example 1: 5 forms a group alone, and 1, 2, 3, 4 have median 2.5, so the total 7.5 rounds to 8. Example 2: one 5 takes a channel alone, the rest 1, 2, 2, 3, 5 have median 2, for a total of 7. Example 3: the two packets each form a group, for a total quality of 3.