【kickstart】2019-A-1

Title description

As a school football coach, your task is to select a team of P students to represent your school.
There are N students for you to choose. The skill level of the i-th student is Si, which is a positive integer and indicates their skill level.
In your opinion, the skills of P players in a reasonable team should be equivalent, so that everyone can be integrated into the team.
In the beginning, you may not be able to directly select a reasonably configured team, so you will provide one-on-one tutoring for some students.
Raising a student's technical level by 1 requires you to spend 1 hour on tutoring.
The season starts soon (in fact, the first game has already started!), so you want to know what the minimum number of training hours you need to provide to train a reasonable team.

Input format

The first line contains an integer T, indicating that there are T groups of test data.
The first row of each set of test data contains two integers N and P.
The second line contains N integers SiSi, where the i-th integer is the skill level of the i-th student.

Output format

Each group of data outputs a result, and each result occupies one line.
The result is expressed as "Case #x: y", where x is the group number (starting from 1) and y is the minimum number of training hours required.

Data range
1≤T≤1001≤T≤1001≤T≤1001≤T≤100,
1≤Si≤100001≤Si≤100001≤Si≤100001≤Si≤10000,
2≤P≤N2≤P≤N2≤P≤ N2≤P≤N,
2≤N≤1052≤N≤1052≤N≤1052≤N≤105

Sample

Input sample:

3
4 3
3 1 9 100
6 2
5 5 1 2 3 4
5 5
7 7 1 7 7

Sample output:

Case #1: 14
Case #2: 0
Case #3: 6

Sample explanation

In sample #1, you can spend a total of 6 hours training the first student and 8 hours training the second student, so that the first three students have the same skill level as 9. This is the shortest time you can spend, so the answer is 14.
In sample #2, you can choose to directly select the first two students without any guidance, so the answer is 0.
In sample #3, P = N, so every student will join your team. You have to spend 6 hours training a third student so that everyone has a skill level of 7. This is the shortest time you can spend, so the answer is 6.

Guess you like

Origin blog.csdn.net/weixin_45349512/article/details/108572967