Educational Codeforces Round 21 C. Tea Party

来源:互联网 发布:景安网络免费空间 编辑:程序博客网 时间:2024/05/29 08:16

传说门


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 volumes a1, 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 108 7
output
6 4 
input
4 41 1 1 1
output
1 1 1 1 
input
3 109 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.



题目大意:n个人 一共w的茶叶。 每个人分的茶叶至少为杯子容积的1/2。先给杯子容积都装满1/2 然后再排序,给大的杯子装满,如果还有茶叶就继续给第二大的杯子装。 一直装到最小的杯子。 


#include <bits/stdc++.h>//#include <ext/pb_ds/tree_policy.hpp>//#include <ext/pb_ds/assoc_container.hpp>//using namespace __gnu_pbds;using namespace std;#define pi acos(-1)#define endl '\n'#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0);#define rand() srand(time(0));typedef long long LL;typedef pair<int, int> pii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=2e5+100;const double EPS=1e-9;const int MOD=1000000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}//typedef tree<pt,null_type,less< pt >,rb_tree_tag,tree_order_statistics_node_update> rbtree;/*lch[root] = build(L1,p-1,L2+1,L2+cnt);    rch[root] = build(p+1,R1,L2+cnt+1,R2);中前*//*lch[root] = build(L1,p-1,L2,L2+cnt-1);    rch[root] = build(p+1,R1,L2+cnt,R2-1);中后*/long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}inline int Scan(){    int res=0,ch,flag=0;    if((ch=getchar())=='-')flag=1;    else if(ch>='0' && ch<='9')res=ch-'0';    while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-'0';    return flag ? -res : res;}int n, m, a[110], b[110], ord[110];bool cmp(int x,int y){    return a[x]>a[y];}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);cin >> n >> m;for(int i = 0; i < n; i++)    {cin >> a[i];b[i] = (a[i]+1) / 2;//先给每个位置都给1/2的茶叶}m -= accumulate(b, b+n, 0);/*int sum = accumulate(vec.begin() , vec.end() , 42);    将sum设置为vec的元素之和再加上42。*/if(m < 0){cout << -1 << endl;return 0;}for(int i=0;i<n;i++)        ord[i]=i;sort(ord, ord+n,cmp);//排序 左边是最大排到右边最小for(int i = 0; i < n; i++){int t = min(m, a[ord[i]]-b[ord[i]]);//如果剩下的容积装满了m还有的话b[ord[i]] += t;m -= t;//m就减少  进入下一个操作}for(int i = 0; i < n; i++)cout << b[i] << (i+1 == n? '\n': ' ');return 0;}



原创粉丝点击