#P8800. [蓝桥杯 2022 国 B] 卡牌
[蓝桥杯 2022 国 B] 卡牌
Problem Description
On this day, Xiaoming is organizing his cards.
He has a total of types of cards. On the -th type of card, a positive integer is printed, and he currently has cards of type .
If there are cards with exactly one card of each type, then these cards are called one set. In order to make as many sets as possible, Xiaoming takes out blank cards. He can write the number on a blank card and treat it as a card of type to form sets. However, Xiaoming feels that handwritten cards do not look nice, so he decides to handwrite at most cards of type .
Please find the maximum number of sets Xiaoming can form.
Input Format
The input has 3 lines.
The first line contains two positive integers and .
The second line contains positive integers .
The third line contains positive integers .
Output Format
One line with one integer representing the answer.
4 5
1 2 3 4
5 5 5 5
3
Hint
[Sample Explanation]
Among these blank cards, take cards to write , and take card to write . Then the number of each type of card becomes , so you can form sets. The remaining blank cards can no longer help Xiaoming form another set.
[Test Case Scale and Assumptions]
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that $n \leq 2 \times 10^{5}; \ a_{i}, b_{i} \leq n; \ m \leq n^{2}$.
Lanqiao Cup 2022 National Contest Group B, Problem C.
Translated by ChatGPT 5