Codeforces Round #239 (Div. 2)

A. Line to Cashier
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.

There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has ki people. The j-th person standing in the queue to the i-th cashier has mi, j items in the basket. Vasya knows that:

  • the cashier needs 5 seconds to scan one item;
  • after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change.

Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of cashes in the shop. The second line contains n space-separated integers: k1, k2, ..., kn (1 ≤ ki ≤ 100), where ki is the number of people in the queue to the i-th cashier.

The i-th of the next n lines contains ki space-separated integers: mi, 1, mi, 2, ..., mi, ki (1 ≤ mi, j ≤ 100) — the number of products thej-th person in the queue for the i-th cash has.

Output

Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.

Sample test(s)
input
1
1
1
output
20
input
4
1 4 3 2
100
1 2 2 3
1 9 1
7 8
output
100
Note

In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.


有多组数,每组给你n个数,让你计算这n个数值的和*5+n*15,让你从这多组数里面找最小的。
//31 ms	 0 KB
#include<stdio.h>
#define inf 0x3f3f3f
int num[1007];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&num[i]);
        int a,count,maxx=inf;
        for(int i=1;i<=n;i++)
        {
            count=0;
            for(int j=1;j<=num[i];j++)
            {
                scanf("%d",&a);
                count+=a;
            }
            count=count*5+num[i]*15;
            if(count<maxx)maxx=count;
        }
        printf("%d\n",maxx);
    }
    return 0;
}

B. Garland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought n colored sheets of paper, the area of each sheet is 1 square meter.

The garland must consist of exactly m pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.

Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​m pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

Input

The first line contains a non-empty sequence of n (1 ≤ n ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.

The second line contains a non-empty sequence of m (1 ≤ m ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

Output

Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

Sample test(s)
input
aaabbac
aabbccac
output
6
input
a
z
output
-1
Note

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color b, three (but not four) sheets of color aand cut a single sheet of color c in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.

In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color z.


Vasya想要做一个手工的花环,于是她去买了n张面积是1的色卡。花环要求m片颜色,每片颜色面积随意。给你两个字符串,每个字母代表一种颜色。第一个代表买的,第二个代表要求的花环,如果能够满足输出花环面积。
如果第二个字符串某种颜色的个数小于第一个串,那么面积加第二个串此字符的个数,否则加第一个串此字符的个数。
//15 ms	 0 KB
#include<stdio.h>
#include<string.h>
using namespace std;
char s1[1007],s2[1007];
struct sa
{
    char a;
    int num;
}p1[107],p2[107];
int main()
{
    while(scanf("%s%s",s1,s2)!=EOF)
    {
        int len1=strlen(s1);
        int len2=strlen(s2);
        int k=0;
        for(int i=0;i<len1;i++)
        {
            int flag=0;
            for(int j=0;j<k;j++)
                if(p1[j].a==s1[i])
                {
                    p1[j].num++;
                    flag=1;
                }
            if(!flag)
            {
                p1[k].a=s1[i];
                p1[k++].num=1;
            }
        }
        int kk=0;
         for(int i=0;i<len2;i++)
        {
            int flag=0;
            for(int j=0;j<kk;j++)
                if(p2[j].a==s2[i])
                {
                    p2[j].num++;
                    flag=1;
                }
            if(!flag)
            {
                p2[kk].a=s2[i];
                p2[kk++].num=1;
            }
        }
        int ok,count=0;
        for(int i=0;i<kk;i++)
        {
            ok=0;
            for(int j=0;j<k;j++)
                if(p2[i].a==p1[j].a)
                {
                    ok=1;
                    if(p1[j].num>=p2[i].num)
                        count+=p2[i].num;
                    else count+=p1[j].num;
                    break;
                }
            if(!ok)break;
        }
        if(!ok)printf("-1\n");
        else printf("%d\n",count);
    }
    return 0;
}

C. Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.

Input

The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.

Output

In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.

Sample test(s)
input
1 1
output
NO
input
5 5
output
YES
2 1
5 5
-2 4
input
5 10
output
YES
-10 4
-2 -2
1 2
给你直角三角形的两条直角边的长度,让你求出此直角三角形的三个顶点坐标,要求三条边不能平行于坐标轴,而且坐标必须为整数。
可以将其中一个顶点固定在(0,0)点,然后判断已给的两条直角边能否由勾股定理形成,如果能说明它们的坐标为整数,最后判断它们形成的长度是否等于直角三角形第三条边的长度以及判断第三条边是否平行于x轴。
//15 ms	 0 KB
#include<stdio.h>
int x1[1007],y1[1007],x2[1007],y2[1007];
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        int k=0,kk=0,flag1=0,flag2=0,c=a*a+b*b;
        for(int i=1;i<a;i++)//将所有能形成a的勾股数找出来
            for(int j=1;j<a;j++)
            {
                if(i*i+j*j==a*a)
                {
                    x1[k]=i;
                    y1[k++]=j;
                    flag1=1;
                    if(i!=j)
                    {
                        x1[k]=j;
                        y1[k++]=i;
                    }
                }
                if(i*i+j*j>a*a)break;
            }
        for(int i=1;i<b;i++)//将所有能形成b的勾股数找出来
            for(int j=1;j<b;j++)
            {
                if(i*i+j*j==b*b)
                {
                    x2[kk]=i;
                    y2[kk++]=j;
                    flag2=1;
                    if(i!=j)
                    {
                        x2[kk]=j;
                        y2[kk++]=i;
                    }
                }
                if(i*i+j*j>b*b)break;
            }
        if(flag1&&flag2)
        {
            int flag=0;
            for(int i=0;i<k;i++)
            {
                for(int j=0;j<kk;j++)
                    if(y1[i]!=y2[j]&&(x2[j]+x1[i])*(x2[j]+x1[i])+(y2[j]-y1[i])*(y2[j]-y1[i])==c)//如果他们不平行于x轴且长度等于直角三角形斜边的长度
                    {
                        printf("YES\n");
                        printf("0 0\n%d %d\n%d %d\n",-x1[i],y1[i],x2[j],y2[j]);
                        flag=1;break;
                    }
                if(flag)break;
            }
            if(!flag)printf("NO\n");
        }
        else printf("NO\n");
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值