luogu#P6977. [NEERC2015] Easy Problemset

[NEERC2015] Easy Problemset

题目描述

Perhaps one of the hardest problems of any ACM ICPC contest is to create a problemset with a reasonable number of easy problems. On Not Easy European Regional Contest this problem is solved as follows.

There are nn jury members (judges). They are numbered from 11 to nn . Judge number ii had prepared pip_{i} easy problems before the jury meeting. Each of these problems has a hardness between 00 and 4949 (the higher the harder). Each judge also knows a very large (say infinite) number of hard problems (their hardness is 5050) . Judges need to select kk problems to be used on the contest during this meeting.

They start to propose problems in the ascending order of judges numbers. The first judge takes the first problem from his list of remaining easy problems (or a hard problem, if he has already proposed all his easy problems) and proposes it. The proposed problem is selected for the contest if its hardness is greater than or equal to the total hardness of the problems selected so far, otherwise it is considered too easy. Then the second judge does the same etc. ; after the n-th judge, the first one proposes his next problem, and so on. This procedure is stopped immediately when kk problems are selected.

If all judges have proposed all their easy problems, but they still have selected less than kk problems, then they take some hard problems to complete the problemset regardless of the total hardness.

Your task is to calculate the total hardness of the problemset created by the judges.

输入格式

The first line of the input file contains the number of judges n(2n10)n (2 \le n \le 10) and the number of problems k(8k14)k (8 \le k \le 14) . The i-th of the following nn lines contains the description of the problems prepared by the i-th judge. It starts with pi(1pi10)p_{i} (1 \le p_{i} \le 10) followed by pip_{i} non negative integers between 00 and 4949 -- the hardnesses of the problems prepared by the i-th judge in the order they will be proposed.

输出格式

Output the only integer -- the total hardness of the selected problems.

题目大意

nn 位出题人,他们要出 kk 道题。他们有一定数量的难度在 004545 之间的简单题,和无限多道难度为 5050 的难题。出题人依次出题,每一位出题人都会选择他剩余的简单题目中的第一道,如果这道题目的难度大于等于之前选择的所有题目的难度之和,则会采用这道题目,否则就会丢弃这道题目。如果一位出题人的所有简单题目都用完了,他就会使用难题。直到选够了 kk 道题目,他们才会停止选题。

3 8
5 0 3 12 1 10
4 1 1 23 20
4 1 5 17 49

94

3 10
2 1 3
1 1
2 2 5

354

提示

Time limit: 1 s, Memory limit: 256 MB.