Codeforces Round #251 (Div. 2)

A. Devu, the Singer and Churu, the Joker
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.

Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly.

The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.

People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.

You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:

  • The duration of the event must be no more than d minutes;
  • Devu must complete all his songs;
  • With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.

If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.

Input

The first line contains two space separated integers nd (1 ≤ n ≤ 100; 1 ≤ d ≤ 10000). The second line contains n space-separated integers: t1, t2, ..., tn (1 ≤ ti ≤ 100).

Output

If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.

Sample test(s)
input
3 30
2 2 1
output
5
input
3 20
2 1 1
output
-1
Note

Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:

  • First Churu cracks a joke in 5 minutes.
  • Then Devu performs the first song for 2 minutes.
  • Then Churu cracks 2 jokes in 10 minutes.
  • Now Devu performs second song for 2 minutes.
  • Then Churu cracks 2 jokes in 10 minutes.
  • Now finally Devu will perform his last song in 1 minutes.

Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.

Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1.

#include<stdio.h>
int s[1007];
int main()
{
    int n,t;
    while(scanf("%d%d",&n,&t)!=EOF)
    {
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
            sum+=s[i];
        }
        int m=(n-1)*10;
        if(m+sum>t){printf("-1\n");continue;}
        int res=t-sum;
        printf("%d\n",res/5);
    }
    return 0;
}

B. Devu, the Dumb Guy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.

Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.

Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.

You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.

Please be careful that answer might not fit in 32 bit data type.

Input

The first line will contain two space separated integers nx (1 ≤ n, x ≤ 105). The next line will contain n space separated integers:c1, c2, ..., cn (1 ≤ ci ≤ 105).

Output

Output a single integer representing the answer to the problem.

Sample test(s)
input
2 3
4 1
output
11
input
4 2
5 1 2 1
output
10
input
3 3
1 1 1
output
6
Note

Look at the first example. Consider the order of subjects: 12. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.

Consider the order of subjects: 21. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.

So overall, minimum of both the cases is 11 hours.

Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.

#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
ll s[100007];
int main()
{
    ll n,x;
    while(scanf("%I64d%I64d",&n,&x)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%I64d",&s[i]);
        sort(s,s+n);
        ll ans=0;
        ans+=s[0]*x;
        for(int i=1;i<n;i++)
            if(x==1)
            {
                ans+=s[i]*x;
            }
            else
            {
                x--;
                ans+=s[i]*x;
            }
        printf("%I64d\n",ans);
    }
    return 0;
}

C. Devu and Partitioning of the Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?

Given an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).

If it is possible to partition the array, also give any possible way of valid partitioning.

Input

The first line will contain three space separated integers nkp (1 ≤ k ≤ n ≤ 105; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array aa1, a2, ..., an (1 ≤ ai ≤ 109).

Output

In the first line print "YES" (without the quotes) if it is possible to partition the array in the required way. Otherwise print "NO" (without the quotes).

If the required partition exists, print k lines after the first line. The ith of them should contain the content of the ith part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.

As there can be multiple partitions, you are allowed to print any valid partition.

Sample test(s)
input
5 5 3
2 6 10 5 9
output
YES
1 9
1 5
1 10
1 6
1 2
input
5 5 3
7 14 2 9 5
output
NO
input
5 3 1
1 2 3 7 5
output
YES
3 5 1 3
1 7
1 2

给你n个数,其中分成n部分,其中k组数的和为偶数,n-k组数的和为奇数,每组数都只能用这n个数里面的某一个

,且每个数只能用一次。

偶数+偶数=偶数,奇数+奇数=偶数,偶数+奇数=奇数。

所以有三种情况不能达到要求:

1.奇数的个数小于n-k

2.偶数的个数+(奇数的个数-(n-k))/2<k

3.奇数的个数-(n-k)是奇数

首先我先构造奇数,每一组一个数,然后构造偶数,分情况进行判断。写得乱了。。。

//77 ms	 800 KB
#include<stdio.h>
int ji[100007],ou[100007];
int main()
{
    int n,k,p;
    while(scanf("%d%d%d",&n,&p,&k)!=EOF)
    {
        int odd=0,even=0,a,kk=p-k;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a);
            if(a&1)ji[odd++]=a;
            else ou[even++]=a;
        }
        if((odd<kk)||(even+(odd-kk)/2<k)||((odd-kk)&1))//不行的情况
        {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
        int i,j;
        for(i=0; i<kk-1; i++)
            printf("1 %d\n",ji[i]);
        if(!k)//如果偶数个数为0,将所有的数都输出来
        {
            printf("%d",n-p+1);
            for(;i<odd;i++)printf(" %d",ji[i]);
            for(j=0;j<even;j++)printf(" %d",ou[j]);
            printf("\n");
            continue;
        }
        else if(i<kk)printf("1 %d\n",ji[i++]);
        int b=odd-kk;
        if(even<k)//如果偶数的个数小于k
        {
            for(int z=0; z<even; z++)
                printf("1 %d\n",ou[z]);
            for(int z=even; z<k-1; z++)
            {
                printf("2 %d %d",ji[i++],ji[i++]);
                printf("\n");
            }
            int count=odd-i;
            printf("%d",count);//输出剩下的所有的奇数
            for(int z=0; z<count; z++)
                printf(" %d",ji[i++]);
            printf("\n");
        }
        else//如果偶数的个数大于k
        {
            for(j=0; j<k-1; j++)
                printf("1 %d\n",ou[j]);
            b+=(even-j);
            if(!b)continue;
            printf("%d",b);
            for(; i<odd; i++)
                printf(" %d",ji[i]);
            for(; j<even; j++)
                printf(" %d",ou[j]);
           printf("\n");
        }

    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值