311287: CF1966A. Card Exchange

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Card Exchangetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have a hand of $n$ cards, where each card has a number written on it, and a fixed integer $k$. You can perform the following operation any number of times:

  • Choose any $k$ cards from your hand that all have the same number.
  • Exchange these cards for $k-1$ cards, each of which can have any number you choose (including the number written on the cards you just exchanged).

Here is one possible sequence of operations for the first example case, which has $k=3$:

What is the minimum number of cards you can have in your hand at the end of this process?

Input

The first line of the input contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 100$, $2 \le k \le 100$) — the number of cards you have, and the number of cards you exchange during each operation, respectively.

The next line of each test case contains $n$ integers $c_1, c_2, \ldots c_n$ ($1 \le c_i \le 100$) — the numbers written on your cards.

Output

For each test case, output a single integer — the minimum number of cards you can have left in your hand after any number of operations.

ExampleInput
7
5 3
4 1 1 4 4
1 10
7
7 2
4 2 1 100 5 2 3
10 4
1 1 1 1 1 1 1 1 1 1
5 2
3 8 1 48 7
6 2
10 20 30 10 20 40
6 3
10 20 30 10 20 40
Output
2
1
1
3
5
1
6
Note

The first example case corresponds to the picture above. The sequence of operations displayed there is optimal, so the answer is $2$.

In the second example case, no operations can be performed, so the answer is $1$.

In the fourth example case, you can repeatedly select $4$ cards numbered with $1$ and replace them with $3$ cards numbered with $1$, until there are $3$ cards left.

Output

题目大意:
你有一手共n张卡片,每张卡片上写有一个数字,还有一个固定的整数k。你可以执行以下操作任意多次:
1. 从你的手中选择任意k张数字相同的卡片。
2. 用这k张卡片交换k-1张卡片,这些卡片上可以写有你选择的任意数字(包括你刚交换的卡片上的数字)。

问:在这个过程中,你的手中可以拥有的最少卡片数量是多少?

输入数据格式:
第一行输入一个整数t(1≤t≤500)——测试用例的数量。接下来是每个测试用例的描述。
每个测试用例的第一行输入两个整数n和k(1≤n≤100,2≤k≤100)——你拥有的卡片数量和每次操作中交换的卡片数量。
每个测试用例的第二行输入n个整数c1,c2,…,cn(1≤ci≤100)——你的卡片上写的数字。

输出数据格式:
对于每个测试用例,输出一个整数——在执行任意次操作后,你的手中可以剩下的最少卡片数量。

示例:
输入:
7
5 3
4 1 1 4 4
1 10
7
7 2
4 2 1 100 5 2 3
10 4
1 1 1 1 1 1 1 1 1 1
5 2
3 8 1 48 7
6 2
10 20 30 10 20 40
6 3
10 20 30 10 20 40
输出:
2
1
1
3
5
1
6题目大意: 你有一手共n张卡片,每张卡片上写有一个数字,还有一个固定的整数k。你可以执行以下操作任意多次: 1. 从你的手中选择任意k张数字相同的卡片。 2. 用这k张卡片交换k-1张卡片,这些卡片上可以写有你选择的任意数字(包括你刚交换的卡片上的数字)。 问:在这个过程中,你的手中可以拥有的最少卡片数量是多少? 输入数据格式: 第一行输入一个整数t(1≤t≤500)——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行输入两个整数n和k(1≤n≤100,2≤k≤100)——你拥有的卡片数量和每次操作中交换的卡片数量。 每个测试用例的第二行输入n个整数c1,c2,…,cn(1≤ci≤100)——你的卡片上写的数字。 输出数据格式: 对于每个测试用例,输出一个整数——在执行任意次操作后,你的手中可以剩下的最少卡片数量。 示例: 输入: 7 5 3 4 1 1 4 4 1 10 7 7 2 4 2 1 100 5 2 3 10 4 1 1 1 1 1 1 1 1 1 1 5 2 3 8 1 48 7 6 2 10 20 30 10 20 40 6 3 10 20 30 10 20 40 输出: 2 1 1 3 5 1 6

加入题单

上一题 下一题 算法标签: