#P16723. [GKS 2019 #A] Training

    ID: 19055 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2019排序前缀和差分Google Kick Start

[GKS 2019 #A] Training

Problem Description

As the football coach at your local school, you have been tasked with picking a team of exactly PP students to represent your school. There are NN students for you to pick from. The ii-th student has a skill rating SiS_i, which is a positive integer indicating how skilled they are.

You have decided that a team is fair if it has exactly PP students on it and they all have the same skill rating. That way, everyone plays as a team. Initially, it might not be possible to pick a fair team, so you will give some of the students one-on-one coaching. It takes one hour of coaching to increase the skill rating of any student by 11.

The competition season is starting very soon (in fact, the first match has already started!), so you'd like to find the minimum number of hours of coaching you need to give before you are able to pick a fair team.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a line containing the two integers NN and PP, the number of students and the number of students you need to pick, respectively. Then, another line follows containing NN integers SiS_i; the ii-th of these is the skill of the ii-th student.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum number of hours of coaching needed, before you can pick a fair team of PP students.

3
4 3
3 1 9 100
6 2
5 5 1 2 3 4
5 5
7 7 1 7 7
Case #1: 14
Case #2: 0
Case #3: 6

Hint

In Sample Case #1, you can spend a total of 66 hours training the first student and 88 hours training the second one. This gives the first, second and third students a skill level of 99. This is the minimum time you can spend, so the answer is 1414.

In Sample Case #2, you can already pick a fair team (the first and second student) without having to do any coaching, so the answer is 00.

In Sample Case #3, P=NP = N, so every student will be on your team. You have to spend 66 hours training the third student, so that they have a skill of 77, like everyone else. This is the minimum time you can spend, so the answer is 66.

Limits

1T1001 \le T \le 100.

1Si100001 \le S_i \le 10000, for all ii.

2PN2 \le P \le N.

Test set 1 (Visible)

2N10002 \le N \le 1000.

Test set 2 (Hidden)

2N1052 \le N \le 10^5.