Gym 100851EEasy Problemset 解题报告

来源:互联网 发布:在线起名字软件 编辑:程序博客网 时间:2024/06/11 15:57

Problem E. Easy Problemset

ACM ICPC 2015–2016, Northeastern European Regional Contest.


Input file: easy.in

Output file: easy.out


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 n jury members (judges). They are numbered from 1 to n. Judge number i had prepared pi easy problems before the jury meeting. Each of these problems has a hardness between 0 and 49 (the higher the harder). Each judge also knows a very large (say infinite) number of hard problems (their hardness is 50). Judges need to select k 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 k problems are selected.


If all judges have proposed all their easy problems, but they still have selected less than k 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.


Input

The first line of the input file contains the number of judges n (2 ≤ n ≤ 10) and the number of problems k(8 ≤ k ≤ 14). The i-th of the following n lines contains the description of the problems prepared by the i-th judge. It starts with pi (1 ≤ pi ≤ 10) followed by pi non negative integers between 0 and 49 — the hardnesses of the problems prepared by the i-th judge in the order they will be proposed.


Output

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



Sample input and output


easy.in 

3 8

5 0 3 12 1 10

4 1 1 23 20

4 1 5 17 49


easy.out

94



easy.in 

3 10

2 1 3

1 1

2 2 5

easy.out

354


In the first example, three problems with hardnesses of 0, 1, and 1 are selected first. Then the first judge proposes the problem with hardness 3 and it is selected, too. The problem proposed by the second judge with hardness 1 is not selected, because it is too easy. Then the problems proposed by the third, the first, and the second judges are selected (their hardnesses are 5, 12 and 23). The following three proposed problems with hardness of 17, 1 and 20 are not selected, and the problemset is completed with a problem proposed by the third judge with hardness of 49. So the total hardness of the problemset is 94.


In the second example, three problems with hardnesses of 1, 1, and 2 are selected first. The second problem of the first judge (hardness 3) is too easy. The second judge is out of his easy problems, so he proposes a problem with hardness 50 and it is selected. The third judge’s problem with hardness 5 is not selected. The judges decide to take 6 more hard problems to complete the problemset, which gives the total hardness of 54 + 6 · 50 = 354.



签到题,题目有点长,读起来有点麻烦。

读取数据,存入数组,而后一列一列地循环即可。

有一种情况,是所有评委手中的简单题都完成判断后,依然凑不够题数。可以把循环的判断条件范围开得大一些,也可以在循环后进行一次判断修正sum的值



#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#define maxn 1000005typedef long long LL;using namespace std;int a[15][15];int main(){    int n,k;    LL sum=0;    int num=0;    freopen("easy.in", "r", stdin);    freopen("easy.out", "w", stdout);    memset(a, -1, sizeof(a));    scanf("%d%d",&n,&k);    for(int i=1;i<=n;i++)    {        int p;        scanf("%d",&p);        for(int j=1;j<=p;j++)            scanf("%d",&a[i][j]);    }    for(int j=1;j<=10;j++)    {        if(num>=k)            break;        for(int i=1;i<=n;i++)        {            if(num>=k)                break;            if(a[i][j]==-1)            {                //表示这个评委手里没有简单题了                num++;                sum+=50;            }            if(a[i][j]>=sum)            {                num++;                sum+=a[i][j];            }        }    }    //有可能所有评委手中的简单题都完成判断后,依然凑不够题数    if(num<k)        sum+=(k-num)*50;    printf("%lld\n",sum);    return 0;}




0 0