Easy ProblemsetInput

Problem E. Easy ProblemsetInput file: easy.inOutput file: easy.outPerhaps one of the hardest problems of any ACM ICPC contest is to create a problemset with a reasonablenumber 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 pieasy problems before the jury meeting. Each of these problems has a hardness between 0 and 49 (thehigher the harder). Each judge also knows a very large (say infinite) number of hard problems (theirhardness 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 firstproblem from his list of remaining easy problems (or a hard problem, if he has already proposed all hiseasy problems) and proposes it. The proposed problem is selected for the contest if its hardness isgreater than or equal to the total hardness of the problems selected so far, otherwise it isconsidered too easy. Then the second judge does the same etc.; after the n-th judge, the first one proposeshis 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, thenthey 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.InputThe 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 thei-th judge. It starts with pi (1 ≤ pi ≤ 10) followed by pi non negative integers between 0 and 49 — thehardnesses of the problems prepared by the i-th judge in the order they will be proposed.OutputOutput the only integer — the total hardness of the selected problems.Sample input and outputeasy.in easy.out3 85 0 3 12 1 104 1 1 23 204 1 5 17 49943 102 1 31 12 2 5354In the first example, three problems with hardnesses of 0, 1, and 1 are selected first. Then the first judgeproposes the problem with hardness 3 and it is selected, too. The problem proposed by the second judgewith hardness 1 is not selected, because it is too easy. Then the problems proposed by the third, thefirst, and the second judges are selected (their hardnesses are 5, 12 and 23). The following three proposedproblems with hardness of 17, 1 and 20 are not selected, and the problemset is completed with a problemproposed 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 secondproblem of the first judge (hardness 3) is too easy. The second judge is out of his easy problems, so heproposes a problem with hardness 50 and it is selected. The third judge’s problem with hardness 5 isnot selected. The judges decide to take 6 more hard problems to complete the problemset, which givesthe total hardness of 54 + 6 · 50 = 354.Page 5 of 14

#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
    freopen("easy.in","r",stdin);
    freopen("easy.out","w",stdout);
    int n,m,i,j,x,top=0,sum=0,maxn=-1;
    int a[12];
    int num[12][12];
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        a[i]=x;
        if(maxn<x)
            maxn=x;
        for(j=1;j<=x;j++)
        {
            cin>>num[i][j];
        }
    }
    for(i=1;i<=maxn;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(a[j]>=i)
            {
                if(num[j][i]>=sum)
                {
                    sum+=num[j][i];
                    top++;
                }
            }
            else
            {
                sum+=50;
                top++;
            }
            if(top>=m)
            break;
        }
        if(top>=m)
        break;
    }
    sum+=(m-top)*50;
    cout<<sum<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值