codeforces 808C
来源:互联网 发布:华硕黄静事件 知乎 编辑:程序博客网 时间:2024/05/22 04:29
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;}
- codeforces 808C
- codeforces 808C
- Codeforces 808C Tea Party
- Codeforces 808C Tea Party
- 【codeforces 808】C.Tea Party(贪心)
- Codeforces 808C Tea Party 题解
- 【Codeforces 808 C. Tea Party】+ sort
- Codeforces 808C Tea Party【贪心】
- 【Codeforces 808C】【贪心】Tea Party题解
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- codeforces #78 div2 C
- Codeforces 117C Cycle
- CodeForces 209C
- CodeForces 156C Cipher
- 动态符号链接的细节
- 2017年上海金马五校程序设计竞赛 Problem C : Count the Number
- 线性回归的概率解释及局部加权回归
- 强大的vim配置文件,让编程更随意
- 你的团队需要一个会讲故事的人-用愿景实现目标
- codeforces 808C
- jsp
- 我的实习面经(Android开发,已拿阿里,华为,CVTE Offer)
- crond和crontab
- JPA学习(三):java持久化查询语言JPQL--介绍、基础语法
- GNU-ld链接脚本浅析
- keras —— 常见问题汇总
- 字节对齐的意义
- 关于crond和crontab