Tea Party

#include <bits/stdc++.h>
#define _xx ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;
struct Node {
    int value, id;
} a[10005];
bool cmp(const Node& t1, const Node& t2) {
    return t1.value < t2.value;
}
int ans[10005];
int main() {
    int n, w;
    while(cin >> n >> w) {
        int now = 0;
        for(int i = 1; i <= n; i++)
        {
            cin >> a[i].value;
            a[i].id = i;
            ans[i] = ceil(a[i].value*1.0/2);
            now += ans[i];
        }
        if(now > w) {
            cout << -1 << endl;
            continue;
        }
        sort(a + 1, a + n + 1, cmp);
        for(int i = n; i >= 1 && now < w; i--) {
            int t = min(w - now, a[i].value - ans[a[i].id]);
            now += t;
            ans[a[i].id] += t;
        }
        if(now < w) {
            cout << -1 << endl;
            continue;
        }
        for(int i = 1; i <= n; i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}

  

posted on 2017-05-18 20:35 NWU_ACM 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/NWUACM/p/6875452.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值