NWU_ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#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  阅读(112)  评论(0编辑  收藏  举报