#P10683. [COTS 2024] 划分 Particija
[COTS 2024] 划分 Particija
Background
Translated from Izborne Pripreme 2024 (Croatian IOI/CEOI Team Selection) D2T1。。
Problem Description
You are given a positive integer 。
A partition of the set is a family of non-empty sets such that:
- , appears in exactly one set。
For example, is a partition of the set 。
A partition can be represented by an array 。Element and element are in the same set if and only if 。The partition mentioned above can be represented by or 。
Patricija has two partitions: the first one is represented by ,and the second one is represented by 。
Patricija wants to know the answer to the following question: if she uses sets from these two partitions to construct a partition of the set ,what is the minimum number of sets needed。
Given a parameter :
- When ,you need to answer the original question。
- When ,you are allowed to change at most one number among the numbers (),and minimize the minimum number of sets needed to construct such a partition。
- When ,you are allowed to change at most one number among the numbers (),and maximize the minimum number of sets needed to construct such a partition。
Note that after your modification, you must ensure that ,。
Input Format
This problem contains multiple test cases within a single input file.
The first line contains two integers ,representing the number of test cases and the parameter.
Then test cases follow.
For each test case, the input contains three lines.
The first line contains a positive integer ,as described above.
The second line contains positive integers, representing 。
The third line contains positive integers, representing 。
Output Format
For each test case, output one line with one integer, representing the required answer。
2 0
4
1 1 2 3
1 2 3 3
7
1 1 1 1 2 3 4
1 2 3 4 4 4 4
2
4
3 1
4
1 1 2 3
1 2 3 3
4
1 1 1 1
1 2 3 3
7
1 1 1 1 2 3 4
1 2 3 4 4 4 4
2
1
2
3 2
4
1 1 2 3
1 2 3 3
4
1 1 1 3
1 2 3 3
7
1 1 1 2 3 4 5
1 2 3 4 4 4 4
3
3
4
Hint
Sample Explanation
Explanation for sample :
For the first test case, the first partition is ,and the second partition is 。Choosing is enough。
For the second test case, the first partition is ,and the second partition is 。Choosing either the first partition or the second partition is enough。
Constraints
For of the data, it is guaranteed that:
- ,;
- ;
- 。
| Subtask ID | Score | Constraints |
|---|---|---|
Translated by ChatGPT 5