首页 > 其他 > 详细

Tea Party

时间:2017-05-18 20:43:41      阅读:363      评论:0      收藏:0      [点我收藏+]
#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;
}

  

Tea Party

原文:http://www.cnblogs.com/NWUACM/p/6875452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!