Codeforces 第 1129 轮(Div. 2)
A
子集选择
Subset Selecting
Codeforces
未评级
原题
←B →

子集选择AI (CI翻译)

You are given an array $a$ of $n$ integers and a positive integer $k$.

给定一个由 $n$ 个整数组成的数组 $a$ 和一个正整数 $k$。AI (CI翻译)

You want to split some of the elements of $a$ into groups $S_1, S_2, \ldots, S_m$ ($m \ge 0$) such that:

你想将 $a$ 中的一部分元素分成若干组 $S_1, S_2, \ldots, S_m$($m \ge 0$),使得:AI (CI翻译)

  • each group contains at least $k$ elements;
  • each element of $a$ belongs to at most one group (an element may also belong to no group at all).
  • 每组至少包含 $k$ 个元素;
  • $a$ 中的每个元素至多属于一个组(也可以不属于任何组)。
AI (CI翻译)

Find the maximum possible value of $\operatorname{mex}(\{\max(S_1), \max(S_2), \ldots, \max(S_m)\})$ over all valid ways to form the groups, where $\operatorname{mex}(c)$ denotes the smallest non-negative integer that does not appear in the collection $c$. If $m = 0$, the collection is empty and $\operatorname{mex}(\{\}) = 0$.

求所有合法分组方案中,$\operatorname{mex}(\{\max(S_1), \max(S_2), \ldots, \max(S_m)\})$ 的最大可能值,其中 $\operatorname{mex}(c)$ 表示未在集合 $c$ 中出现的最小非负整数。如果 $m = 0$,则该集合为空,且 $\operatorname{mex}(\{\}) = 0$。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

每个测试包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 500$)。接下来是各组测试用例的描述。AI (CI翻译)

The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the length of the array $a$ and the minimum allowed size of each group.

每组测试用例的第一行包含两个整数 $n$ 和 $k$($1 \le k \le n \le 100$)——分别表示数组 $a$ 的长度和每组允许的最少元素个数。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le n$) — the elements of the array $a$.

每组测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($0 \le a_i \le n$)——表示数组 $a$ 的元素。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a single integer — the maximum possible value of $\operatorname{mex}(\{\max(S_1), \max(S_2), \ldots, \max(S_m)\})$ over all valid ways to form the groups.

对于每组测试用例,输出一个整数——所有合法分组方案中,$\operatorname{mex}(\{\max(S_1), \max(S_2), \ldots, \max(S_m)\})$ 的最大可能值。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, one optimal way is to form the groups $\{0\}$, $\{1\}$, $\{2\}$, which gives $\operatorname{mex}(\{0, 1, 2\}) = 3$.

在第一组测试用例中,一种最优方案是分成 $\{0\}$、$\{1\}$、$\{2\}$ 这几组,此时 $\operatorname{mex}(\{0, 1, 2\}) = 3$。AI (CI翻译)

In the second test case, one optimal way is to form the single group $\{1, 2, 3, 4\}$, which gives $\operatorname{mex}(\{4\}) = 0$.

在第二组测试用例中,一种最优方案是只分成一组 $\{1, 2, 3, 4\}$,此时 $\operatorname{mex}(\{4\}) = 0$。AI (CI翻译)

In the third test case, one optimal way is to form the groups $\{0, 0\}$ and $\{1, 1\}$, which gives $\operatorname{mex}(\{0, 1\}) = 2$.

在第三组测试用例中,一种最优方案是分成 $\{0, 0\}$ 和 $\{1, 1\}$ 两组,此时 $\operatorname{mex}(\{0, 1\}) = 2$。AI (CI翻译)

样例

Input #1
6
3 1
0 2 1
4 2
1 2 3 4
5 2
0 1 0 1 0
5 4
0 0 1 0 0
5 1
4 0 0 0 2
6 2
0 0 2 1 0 0
Output #1
3
0
2
1
1
3
InputCopy OutputCopy
题目信息
题号
2277A
时间限制
1 s
内存限制
256 MB
标签
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。