#P16881. [GKS 2022 #D] Image Labeler

    ID: 19209 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学贪心2022Special Judge排序Google Kick Start

[GKS 2022 #D] Image Labeler

Problem Description

Crowdsource is organizing a campaign for Image Labeler task with participants across NN regions. The number of participants from each of these regions are represented by A1,A2,,ANA_1, A_2, \ldots, A_N.

In the Image Labeler task, there are MM categories. Crowdsource assigns participants to these categories in such a way that all participants from a region are assigned to the same category, and each category has at least one region assigned to it. The success metric of the campaign is measured by the sum of medians of the number of participants in each category. (Let us remind you here that the median of a list of integers is the "middle" number when those numbers are sorted from smallest to largest. When the number of integers in a list is even, we have 22 "middle" numbers, therefore the median is defined as the arithmetic mean (average) of the 22 middle values.)

For example, imagine that we have N=3N = 3 regions with A1=5A_1 = 5, A2=8A_2 = 8, and A3=9A_3 = 9 participants respectively and we want to assign them to M=2M = 2 categories. If we assign regions 22 and 33 to category 11 and region 11 to category 22, then the success metric would be $\operatorname{median}(\{A_2 = 8, A_3 = 9\}) + \operatorname{median}(\{A_1 = 5\}) = \frac{8+9}{2} + 5 = 8.5 + 5 = 13.5$. We can also assign regions 11 and 22 to category 11 and region 33 to category 22. Then the success metric would be equal to the sum of the median of {A1=5,A2=8}\{A_1 = 5, A_2 = 8\} and the median of {A3=9}\{A_3 = 9\}, which is 5+82+9=6.5+9=15.5\frac{5+8}{2} + 9 = 6.5 + 9 = 15.5.

Your task is to find the maximum possible value of the success metric that can be obtained by assigning participants in regions to the categories.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow.

The first line of each test case contains two integers NN and MM: the number of regions, and the number of categories respectively.

The next line contains NN integers A1,A2,,ANA_1, A_2, \ldots, A_N.

Output Format

For each test case, output one line containing Case #xx: yy, where xx is the test case number starting from 11 and yy is the maximum possible value of the success metric.

yy will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

1
3 2
11 24 10
Case #1: 34.5
1
5 1
6 2 5 1 9
Case #1: 5.0

Hint

In this test, we can assign participants in regions to categories in 66 possible ways:

  • Assign {11,24}\{11, 24\} to category 11 and {10}\{10\} to category 22, in which case the success metric is 11+242+10=17.5+10=27.5\frac{11+24}{2} + 10 = 17.5 + 10 = 27.5.
  • Assign {24,10}\{24, 10\} to category 11 and {11}\{11\} to category 22, in which case the success metric is 24+102+11=17+11=28\frac{24+10}{2} + 11 = 17 + 11 = 28.
  • Assign {11,10}\{11, 10\} to category 11 and {24}\{24\} to category 22, in which case the success metric is 11+102+24=10.5+24=34.5\frac{11+10}{2} + 24 = 10.5 + 24 = 34.5.
  • 33 other ways, where assignments to category 11 and 22 are swapped, which does not alter the value of success metric.

So, the maximum possible value of the success metric is 34.534.5.

Limits

1T1001 \le T \le 100.

1N1041 \le N \le 10^4.

1M1041 \le M \le 10^4.

1MN1 \le M \le N.

1Ai1051 \le A_i \le 10^5, for all ii.

Test Set 11

0NM10 \le N - M \le 1.

Test Set 22

No additional constraints.