CF2277A Subset Selecting

Description

[Olivia Rodrigo - the cure](https://open.spotify.com/track/4EoJ151oQ5jY48z4RhSE96) You are given an array $ a $ of $ n $ integers and a positive integer $ k $ . You want to split some of the elements of $ a $ into groups $ S_1, S_2, \ldots, S_m $ ( $ m \ge 0 $ ) such that: - 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). 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 $ .

Input Format

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. 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. 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 $ .

Output Format

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.

Explanation/Hint

In the first test case, one optimal way is to form the groups $ \{0\} $ , $ \{1\} $ , $ \{2\} $ , which gives $ \operatorname{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 $ \operatorname{mex}(\{4\}) = 0 $ . 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 $ .