cswork / OAOpen practice workspace

AmazonOA #105

Channels Max Quality

Estimated MediumJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

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).

Input

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

Output

Output a single integer answer.

Example 1

Input:

5 2
1 2 3 4 5

Output:

8

Example 2

Input:

6 2
5 2 2 1 5 3

Output:

7

Example 3

Input:

2 2
1 2

Output:

3

Example notes

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.

Editorial

Loading solution…