#P9317. [EGOI 2022] SubsetMex / 子集 mex
[EGOI 2022] SubsetMex / 子集 mex
Background
Day 1 Problem A.
The statement is translated from EGOI2022 subsetmex。
Problem Description
A multiset is a set in which elements may appear multiple times. For example, is a multiset.
You are given a multiset with values in , and a target natural number (). Your goal is to make by repeatedly performing the following operation some number of times:
- Choose a (possibly empty) subset , where contains no duplicate elements.
- Delete the elements of from . (If an element appears multiple times, remove only one copy.)
- Insert into , where is the smallest natural number that is not in . stands for “minimum excluded value”.
You need to find the minimum number of operations needed to make .
Since can be very large, it is given as a list of length , , where denotes how many times appears in . (Recall that is the element we want to insert into .)
Input Format
The first line contains an integer , the number of test cases. Then each test case is described in two lines:
- The first line of each test case contains an integer , the element to be inserted into .
- The second line contains integers , describing the multiset as above.
Output Format
For each test case, output one line containing one integer, the minimum number of operations.
2
4
0 3 0 3
5
4 1 0 2 0
4
10
Hint
Explanation for Sample .
Initially, , and the goal is to make . We can do the following operations:
- Let , then .
- Let , then .
- Let , then .
- Let , then .
Constraints
For all testdata, , , .
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): and .
- Subtask 7 ( points): and .
- Subtask 8 ( points): No special constraints.
Input Format
Output Format
Translated by ChatGPT 5
