Educational Codeforces Round 21 C. Tea Party

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

Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumesa1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that:

  • Every cup will contain tea for at least half of its volume
  • Every cup will contain integer number of milliliters of tea
  • All the tea from the teapot will be poured into cups
  • All friends will be satisfied.

Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj.

For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.

Input

The first line contains two integer numbers n and w (1 ≤ n ≤ 100).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100).

Output

Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.

If it's impossible to pour all the tea and satisfy all conditions then output -1.

Examples
input
2 10
8 7
output
6 4 
input
4 4
1 1 1 1
output
1 1 1 1 
input
3 10
9 8 10
output
-1
Note

In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available.


觉得这题挺有趣的..  不过直接暴力过了  不知道还有没有什么更好地方法  

见注释





#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<queue>
#include<cmath>
#include<stack>
#include<list>
#include<map>
using namespace std;
typedef long long ll;


int a[105];
int b[105];
int main()
{
    int n,w,i,j,k;
    while(scanf("%d%d",&n,&w)==2)
    {

        int sum2=0;
        int w1=w;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=a[i];
            if(a[i]%2==0)
            {
                sum2+=a[i]/2;
                b[i]-=a[i]/2;      //相当于已经在a[i]中倒了一半的水 b[i]为剩下的容量
                w1-=a[i]/2;         //壶里还剩下多少茶
            }
            else
            {
                sum2+=a[i]/2+1; //与if语句同理
                b[i]-=a[i]/2+1;
                w1-=a[i]/2+1;
            }
        }
        if(w1<0)   //茶不够
        {
            printf("-1\n");
            continue;
        }
        while(w1!=0)   //这题n比较小 w的最大值也很小 直接暴力过了..没想到这么水..
        {
            int t=0;
            int maxn=-1;
            for(i=1;i<=n;i++)
            {
                if(b[i]>maxn)      //求出剩余容量最大的那个 容器的容量大的比容量小的 装满一半后 未装一半的容量肯定还大 else if中有个特例
                {
                    maxn=b[i];
                    t=i;
                }
                else if(b[i]==maxn)
                {
                    if(a[i]%2==1)  // 若a[i]==9 则剩下4 若a[i]==8 也剩下4  根据题意我们要优先装容量大的 所以要记录a[i]为奇数的下标
                    {
                        t=i;
                    }
                }
            }
            if(w1-b[t]>=0) //if else 里语句很好理解吧..
            {
             w1-=b[t];
             b[t]=0;
            }
            else
            {
                b[t]-=w1;
                w1=0;
            }

        }
        for(i=1;i<=n;i++)
        {
            printf("%d%c",a[i]-b[i],i==n?'\n':' ');  //输出a[i]-b[i],就是最终结果了
        }

    }

    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值