Orig Description
Translation
Quiz
You are a director of a quiz show. There are N participants scheduled to appear as answerers in the quiz show, each of whom is numbered from 1 to N.
The quiz plans to ask M+1 questions, each of which is numbered from 1 to M+1. The questions are asked in order of their numbers, and only the first person to answer correctly by pressing the buzzer will get the points. The score of the i-th question is an integer Si. The person with the highest total score at the end of the M+1-th question will win. However, if there are multiple persons with the highest score, no one will win.
You have decided the scores for the first M questions and are now considering the score for the last question, which is usually set to a score that anyone can turn around. However, if the score for the last question is determined based on the participants' total scores at that time, it may discourage the participants from doing their best. Therefore, you have decided to set the score for the last question in advance so that all participants will have a chance to turn the game around no matter what the score situation may be.
Fortunately, it is known which participants can answer correctly for questions 1 to M. For the M+1-th question, all participants can answer correctly. Only one person among those who can answer correctly will get the score Si for the M+1-th question. The answer to the question is closed as soon as the answerer who answered correctly appears, and the same answerer can answer the question as many times as he or she wants. Therefore, you do not need to consider the score Si of the question if no one can get it. Also, multiple answerers will not share the score Si of a question that they answered correctly or share the score.
Given the information about the scores for each question and the participants who can answer correctly, find the minimum score SM+1 for the last question so that anyone can win the game by answering correctly regardless of the score situation.
Input
The input consists of multiple datasets, each in the following format.
N M
S1 k1 c1,1 ... c1,k1
...
SM kM cM,1 ... cM,kM
The first line contains two integers N and M, the number of answerers and the number of questions except the last one.
For questions 1 to M, information about the participants who can answer correctly is given. The i-th line contains the score Si for the i-th question, the number of participants ki who can answer the question correctly, and the numbers ci,1 ... ci,ki of the participants who can answer the question.
The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 30.
All integers in the input are positive integers that satisfy the following conditions.
2 ≤ N ≤ 10,000
1 ≤ M ≤ 1,000
1 ≤ Si ≤ 100
1 ≤ ki ≤ N
1 ≤ ci,1 < ... < ci,ki ≤ N
Σki ≤ 100,000
Note that the output value of SM+1 may exceed this range.
Output
For each dataset, output the minimum value of SM+1 that satisfies the above condition in one line.
Sample Input
3 2
5 2 1 3
8 2 2 3
2 3
8 2 1 2
3 1 1
Extracted Specification
An integer N (2 ≤ N ≤ 10,000), representing some quantity.
An integer M (1 ≤ M ≤ 1,000), representing another quantity.
A list of tuples (S, k, c1, ..., ck) for i from 1 to M, where:
- S is an integer (1 ≤ S ≤ 100),
- k is an integer (1 ≤ k ≤ N),
- c1, ..., ck are integers (1 ≤ c1 < ... < ck ≤ N).
The input ends with a pair of zeros.
### Example Input:
```
3 2
5 2 1 3
8 2 2 3
2 3
8 2 1 2
3 1 1
0 0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, int, List[Tuple[int, int, List[int]]]]]):
'''
inputs: a list of tuples, each containing:
- two integers
- a list of tuples, each containing:
- one integer
- one integer
- a list of integers
'''
Test Case Generator
Sure, here is a test case generator for the provided problem statement:
```python
import random
def tcgen():
# Generate the number of participants (N) and the number of questions (M)
N = random.randint(2, 10000)
M = random.randint(1, 1000)
# Initialize list to hold the test data
test_data = []
# Generate the questions with scores and participants who can answer
for _ in range(M):
S = random.randint(1, 100)
k = random.randint(1, N)
c = sorted(random.sample(range(1, N + 1), k))
test_data.append((S, k, c))
return N, M, test_data
def format_test_case(N, M, test_data):
formatted_test_case = f"{N} {M}\n"
for S, k, c in test_data:
formatted_test_case += f"{S} {k} " + " ".join(map(str, c)) + "\n"
return formatted_test_case
# Generate a test case
N, M, test_data = tcgen()
formatted_test_case = format_test_case(N, M, test_data)
print(formatted_test_case)
```
### Explanation:
1. **Generating N and M:**
- N is the number of participants, randomly chosen between 2 and 10,000.
- M is the number of questions, randomly chosen between 1 and 1,000.
2. **Generating the score and participants for each question:**
- For each question, a score `S` is randomly chosen between 1 and 100.
- The number of participants `k` who can answer the question is randomly chosen between 1 and N.
- A list `c` of `k` distinct participants is created using `random.sample` to ensure no duplicates and sorted to maintain order.
3. **Formatting the test case:**
- The `format_test_case` function constructs the input format required for the problem by iterating through the generated test data.
This code will produce a test case in the format required by the problem statement. Each run will generate a different test case due to the use of randomization. You can call `tcgen` multiple times to generate multiple test cases.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
line = fh.readline().strip()
if line == "0 0":
break
N, M = map(int, line.split())
questions = []
for _ in range(M):
parts = list(map(int, fh.readline().strip().split()))
Si = parts[0]
ki = parts[1]
participants = parts[2:]
questions.append((Si, ki, participants))
datasets.append((N, M, questions))
return datasets