#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<iomanip>
using namespace std;
int n, k;
typedef struct node{
int index;
int capacity;
int actual_size;
}node;
bool compare(node a, node b){
return a.capacity > b.capacity;
}
int main(){
while (cin >> n >> k){
vector<node> cup;
int sum = 0;
for (int i = 0; i < n; i++){
node m;
cin >> m.capacity;
m.index = i;
cup.push_back(m);
sum += m.capacity;
}
if (sum / 2 > k){
cout << "-1" << endl;
}
else{
bool flag = false;
sort(cup.begin(), cup.end(), compare);
for (int i = 0; i < cup.size(); i++){
cup[i].actual_size = ceil(cup[i].capacity / (double)2);
k -= cup[i].actual_size;
if (k < 0){
cout << "-1" << endl;
flag = true;
break;
}
}
if (flag) continue;
int i = 0;
while (k){
if (k >(cup[i].capacity - cup[i].actual_size)){
k -= (cup[i].capacity - cup[i].actual_size);
cup[i].actual_size = cup[i].capacity;
}
else{
cup[i].actual_size += k;
k = 0;
}
i++;
}
vector<int> res(n);
for (int i = 0; i < cup.size(); i++){
int index = cup[i].index;
res[index] = cup[i].actual_size;
}
for (int i = 0; i < res.size(); i++){
cout << res[i] << " ";
}
cout << endl;
}
}
return 0;
}
Codeforces 808C Tea Party
最新推荐文章于 2018-08-17 01:04:15 发布