#K46297. Minimum Book Titles Required
Minimum Book Titles Required
Minimum Book Titles Required
You are given several test cases. In each test case, there are B book titles available, each with a certain stock (although the stock information is not used in this problem) and C customers. Each customer requests one book by specifying the index (0-based) of the book title they want. Your task is to determine the minimum number of different book titles that must be supplied to satisfy all customer orders.
In other words, if the customers request the same title multiple times, that title only needs to be supplied once. Formally, if we denote the list of customer requests as \( R = [r_1, r_2, \dots, r_C] \), then the answer for a test case is the number of unique values in \(R\).
Note: The stock numbers provided for each book do not affect the answer.
inputFormat
The input is read from standard input. It begins with an integer \(T\) denoting the number of test cases. For each test case, the following lines are given:
- An integer \(B\) representing the number of books.
- A line containing \(B\) space-separated integers representing the stock for each book title (this data is not used in the solution).
- An integer \(C\) representing the number of customers.
- If \(C > 0\), a line containing \(C\) space-separated integers, each representing the 0-based index of the book requested by a customer.
All inputs are provided via standard input (stdin).
outputFormat
For each test case, print a single line with one integer, which is the minimum number of different book titles required to fulfill all customer orders. The output should be printed to standard output (stdout).
## sample2
5
2 3 1 4 6
4
0 1 2 2
4
8 1 2 2
3
1 1 0
3
2