#P11006. [蓝桥杯 2024 省 Python B] 纯职业小组
[蓝桥杯 2024 省 Python B] 纯职业小组
Problem Description
In the Lanqiao Kingdom, the king commands a powerful army made up of squads. Each squad consists of soldiers of the same profession. Specifically, the -th squad contains soldiers whose profession is .
Recently, the king plans to hold a grand military parade in the palace square to celebrate the kingdom’s prosperity. However, while the soldiers were entering, a sudden storm disrupted their formation, mixing soldiers from different squads together and completely messing up the order.
Although the king cannot know the exact profession of each individual soldier, to ensure the ceremony can proceed smoothly, the king plans to select some of these chaotic soldiers to form “pure-profession groups” for inspection. A “pure-profession group” is defined as a team of soldiers of the same profession.
Ask: what is the minimum number of soldiers the king must select to guarantee that these soldiers can form “pure-profession groups”?
Input Format
The first line contains an integer , indicating that the input contains test cases.
The following describes the test cases in order.
For each test case, the first line contains two integers and , separated by a space, representing the number of squads and the number of pure-profession groups to form.
The next lines each contain two integers and , separated by a space, representing the profession and the number of soldiers in the -th squad.
Output Format
Output lines. Each line contains one integer, representing the answer for each test case: the minimum number of soldiers the king must select to form “pure-profession groups”. If it is impossible to form “pure-profession groups” no matter what, output .
2
3 2
1 3
2 3
3 3
3 5
1 3
2 3
3 3
8
-1
Hint
For of the test cases, , , , .
For all test cases, , , , .
Sample Explanation
In the first sample, to form “pure-profession groups”, the king must select at least soldiers. If only soldiers are selected, then the professions of these soldiers could be , making it impossible to form “pure-profession groups”.
In the second sample, even if all soldiers are selected, it is still impossible to form “pure-profession groups”, so output .
Translated by ChatGPT 5