#P6977. Judges and Problem Hardness
Judges and Problem Hardness
Judges and Problem Hardness
In the Not Easy European Regional Contest, judges are tasked with selecting k problems for the contest. There are n judges, numbered from 1 to n. Judge i has prepared pi easy problems (each with a hardness between 0 and 49), and an infinite number of hard problems (each with hardness 50).
The judges propose problems in the order of their numbers in rounds. In each turn, a judge proposes the next available problem from his list of easy problems; if he has no easy problems left, he proposes a hard problem.
A proposed problem is selected if its hardness is at least as high as the total hardness of the problems selected so far. Otherwise, it is discarded. This round-robin process continues until k problems have been selected. However, if all judges have exhausted their easy problems and fewer than k problems have been selected, the remaining problems are chosen as hard problems (each with hardness 50) without considering the hardness condition.
Your task is to compute the total hardness of the final problem set.
The selection condition in formula form is:
\(h \geq T\)
where \(h\) is the hardness of the proposed problem and \(T\) is the total hardness of the problems selected so far.
inputFormat
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000) — the number of judges and the number of problems to be selected.
Each of the following n lines corresponds to one judge. Each line starts with an integer pi (0 ≤ pi ≤ 100), the number of easy problems prepared by judge i, followed by pi integers. These integers represent the hardness values of the easy problems in the order they will be proposed (each between 0 and 49).
outputFormat
Output a single integer — the total hardness of the chosen problem set.
sample
3 3
2 0 10
1 3
1 4
7
</p>