Problem p01925 - Generation 3

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 or size.
An integer M (1 ≤ M ≤ 1,000), representing another quantity or size.
M lines follow, each containing:
- An integer Si (1 ≤ Si ≤ 100).
- An integer ki (1 ≤ ki ≤ N).
- A list of ki integers, each between 1 and N.
The input ends with a line containing two zeros.

### Example Input:

```
3 2
5 2 1 3
8 2 2 3
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, where each tuple contains:
        - an integer N
        - an integer M
        - a list of M tuples, where each tuple contains:
            - an integer Si
            - an integer ki
            - a list of ki integers 
    '''
    

Test Case Generator

Sure, here is a test case generator for the given problem statement:

```python
import random

def generate_test_case():
    # Number of answerers (N)
    N = random.randint(2, 10000)

    # Number of questions except the last one (M)
    M = random.randint(1, 1000)

    # List to store the scores and participants for each question
    questions = []

    # Generate questions
    for i in range(M):
        Si = random.randint(1, 100)  # score for the i-th question
        k = random.randint(1, N)  # number of participants who can answer the question
        participants = sorted(random.sample(range(1, N+1), k))  # list of participants who can answer the question
        questions.append((Si, k, participants))

    # Generate the input string
    input_data = f"{N} {M}\n"
    for Si, k, participants in questions:
        input_data += f"{Si} {k} " + " ".join(map(str, participants)) + "\n"
    
    # Add the end of input indicator
    input_data += "0 0\n"

    return input_data

# Generate a test case
test_case = generate_test_case()
print(test_case)
```

This generator creates a random test case for the given problem. Here's how it works:
- It generates a random number of participants `N` and a random number of questions `M` (excluding the last one).
- For each of the `M` questions, it generates a random score `Si` between 1 and 100, a random number of participants `k` who can answer the question, and a sorted list of `k` unique participants.
- It then formats these values into the required input format and adds the end-of-input indicator (`0 0`).

You can run this script to generate random test cases for the problem statement.

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):
            data = list(map(int, fh.readline().strip().split()))
            Si = data[0]
            ki = data[1]
            participants = data[2:]
            questions.append((Si, ki, participants))
        datasets.append((N, M, questions))
    return datasets