Tea Party time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard 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 10 8 7 output 6 4 input 4 4 1 1 1 1 output 1 1 1 1 input 3 10 9 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. 水题,直接上代码,但是CF上第12组数据无法通过,系统自动容错,自己编译器也无法通过
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int main( ){ int n,w,sum,wa; int q,max_num; int num1[105]; int num2[105]; int sum_num; int num3[105]; scanf("%d%d",&n,&w); wa = 0; memset(num3, 0, sizeof(num3)); sum=0; q=-1; sum_num=0; max_num=-1; for(int i=1;i<=n;i++){ scanf("%d",&num1[i]); num2[i]=num1[i]; num3[i]=(num1[i]+1)/2; sum+=num1[i]; sum_num+=num3[i]; } if(sum == w) { for(int i=1;i<=n;i++) printf("%d ",num2[i]); return 0; } if(w<sum_num) printf("-1\n"); else{ w-=sum_num; do{ num2[q]=-2; max_num=-1; for(int i=1;i<=n;i++) if(max_num<num2[i]){ max_num=num2[i]; q=i; } if(w<=(num2[q]-num3[q])){ num3[q]+=w; w=0; } else { w-=(num2[q]-num3[q]); num3[q]=num1[q]; } }while(w!=0); for(int i=1;i<=n;i++) printf("%d ",num3[i]); } return 0; }