CF-2277A•Codeforces

Subset Selecting

greedy

Olivia Rodrigo - the cure

You are given an array aa of nn integers and a positive integer kk.

You want to split some of the elements of aa into groups S1,S2,…,SmS1,S2,…,Sm (m≥0m≥0) such that:

  • each group contains at least kk elements;
  • each element of aa belongs to at most one group (an element may also belong to no group at all).

Find the maximum possible value of mex({max(S1),max(S2),…,max(Sm)})mex({max(S1),max(S2),…,max(Sm)}) over all valid ways to form the groups, where mex(c) denotes the smallest non-negative integer that does not appear in the collection c. If m=0, the collection is empty and mex({})=0.

Input

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

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

The second line of each test case contains n integers a1,a2,…,an (0≤ai≤n) — the elements of the array a.

Output

For each test case, output a single integer — the maximum possible value of mex({max(S1),max(S2),…,max(Sm)}) over all valid ways to form the groups.

Note

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

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

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

Sample 1
Input
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
3
0
2
1
1
3

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments