Coruscant

View as PDF

Submit solution

Points: 0.00
Time limit: 3.0s
Memory limit: 1G
Input: stdin
Output: stdout

Author:
Problem type
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

The Jedi Trials can be considered an exam in the Jedi Temple, which tests Padawans many important skills before promoting them to be Jedi Knights, which include Force abilities, mental discipline, etc. Lightsabers are versatile and powerful weapons, so it is required for a Padawan to master them. Therefore, a lightsaber duel is one of the most appealing phases during the Jedi Trials. The upcoming Jedi Trials will be the competition of ~k~ Padawans.

In preparation for the upcoming Jedi Trials, Master Yoda has made ~n~ (~n \geq k~) lightsabers; the ~i~-th lightsaber has the length ~l_i~. In order to ensure fairness between all Padawans during the lightsaber duel, the two lightsabers of two Padawans in the duel must have the same length. Because there are ~k~ Padawans, Yoda needs to have at least ~k~ lightsabers that have equal lengths.

Because it consumes a lot of time to make new lightsabers, Yoda chooses to adjust the length of existing ones. Yoda prefers the short lightsabers over long lightsabers because they highlight more skills from Padawans, such as reflexes and versatility. Thus, he will only shorten lightsabers but not lengthen them. Yoda wants to know at least how many lightsabers he has to shorten before obtaining ~k~ lightsabers that have the same length. Can you help him?

Input

Each test contains multiple test cases. The first line contains the number of test cases ~t~ (~1 \leq t \leq 10^4~). The description of the test cases is as follows.

The first line of each test case contains two integers ~n, k~ (~1 \leq k \leq n \leq 10^6~), the number of lightsabers that Yoda made and the number of Padawans, respectively.

The next line of each test case contains ~n~ integers ~l_1, l_2, \dots, l_n~ (~1 \leq l_i \leq 10^9~), lengths of the lightsabers.

The sum of ~n~ over all test cases does not exceed ~10^6~.

Output

For each test case, print the minimum number of lightsabers to be shortened before getting ~k~ lightsabers having equal length.

Sample Input 1

3
4 2
1 2 3 4
6 6
1 1 1 1 1 1
5 4
4 4 4 3 2

Sample Output 1

1
0
3

Comments

Please read the guidelines before commenting.


There are no comments at the moment.