Polycarp invited all his friends to the tea party to celebrate the holiday. He has ncups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores wmilliliters 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.

题目链接:CodeForces - 808C

题意:

给你一个含有w升水的茶壶,以及N个杯子,每一个杯子的容量为ai升,

让给你这N个杯子倒水,使之满足以下条件:

1.每一个杯子至少有一半以上的水,(包含一半

2.每一个杯子中水的含量为整升

3.茶壶的水全倒完。

4,不存在这样一对杯子,A和B,A的体积大于B的体积,但是A杯子中的水比B少。

不能满足就输出-1,能满足就输出这N个杯子中分别的水量。

思路:创建一个结构体来描述杯子,

然后先把所有杯子加入一半的水。如果不能完成这样,就输出-1.

然后排序,以杯子的体积从大到小加满水,然后输出答案就好了。

细节见我的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct node
{
int v;
int id;
}a[maxn];
int n,w;
bool cmp(node one,node two)
{
return one.v<two.v;
} int ans[maxn];
int main()
{
gg(n);
gg(w);
repd(i,,n)
{
gg(a[i].v);
a[i].id=i; }
sort(a+,a++n,cmp);
repd(i,,n)
{
ans[a[i].id]=(a[i].v+)>>;
w-=ans[a[i].id];
}
if(w<)
{
printf("-1\n");
return ;
}
for(int i=n;i>=;i--)
{
if(w>=(a[i].v-ans[a[i].id]))
{
w-=(a[i].v-ans[a[i].id]);
ans[a[i].id]=a[i].v;
}else
{
// w=0;
ans[a[i].id]+=w;
w=;
}
}
repd(i,,n)
{
printf("%d ",ans[i] );
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Tea Party CodeForces - 808C (构造+贪心)的更多相关文章

  1. CodeForce-808C Tea Party(结构体排序贪心)

    Tea Party CodeForces - 808C 现在有 n 个杯子,每个杯子的容量为 a1, a2, ..., an.他现在一共有 w 毫升茶 (w ≤ a1 + a2 + ... + an) ...

  2. CodeForces - 158B.Taxi (贪心)

    CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...

  3. Codeforces Round #301 (Div. 2) B. School Marks 构造/贪心

    B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/probl ...

  4. Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列

    A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...

  5. Codeforces Round #650 (Div. 3) D. Task On The Board (构造,贪心)

    题意:有一个字符串和一组数,可以对字符串删去任意字符后为数组的长度,且可以随意排序,要求修改后的字符串的每个位置上的字符满足:其余大于它的字符的位置减去当前位置绝对值之和等于对应序列位置上的数. 题解 ...

  6. Codeforces 976 正方格蛇形走位 二维偏序包含区间 度数图构造 贪心心火牧最大dmg

    A #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; int main() { i ...

  7. Codeforces 1304D. Shortest and Longest LIS 代码(构造 贪心)

    https://codeforces.com/contest/1304/problem/D #include<bits/stdc++.h> using namespace std; voi ...

  8. Codeforces Round #649 (Div. 2) C. Ehab and Prefix MEXs (构造,贪心)

    题意:有长度为\(n\)的数组\(a\),要求构造一个相同长度的数组\(b\),使得\({b_{1},b_{2},....b_{i}}\)集合中没有出现过的最小的数是\(a_{i}\). 题解:完全可 ...

  9. Codeforces Global Round 9 B. Neighbor Grid (构造,贪心)

    题意:给一个\(n\)X\(m\)的矩阵,矩阵中某个数字\(k\)表示其四周恰好有\(k\)个不为0的数字,你可以使任意位置上的数字变大,如果操作后满足条件,输出新矩阵,否则输出NO. 题解:贪心,既 ...

随机推荐

  1. 洗礼灵魂,修炼python(80)--全栈项目实战篇(8)—— 计算器

    用正则表达式开发一个计算器,计算用户给定的一串带有加减乘除的公式. 要求:不能使用eval转换字符串 分析: 要求简单,就是计算混合运算,但是不能使用eval直接转换,主要就是把整个式子中的小括号优先 ...

  2. 三、Tableau筛选器的使用

    一.使用筛选器制作联动效果 注意,下面两幅图以‘是否盈利’来添加颜色标签 图一:地图 图二:月度销售客户细分 图三:月度销售产品类别 1.新增仪表盘:将图一.图二.图三拉进同一个仪表盘 2.在图一原图 ...

  3. Node中的模块引入机制

    1.如果模块在当前目录下,可以通过下面语句将模块引入进来,注意需要使用 "./"表示当前路径 const currency = require('./currency'); ←-- ...

  4. Linux中shell和子shell一点点理解

    Linux执行脚本有两种方式,主要区别在于是否建立子shell   1.像sh,bash,./命令是用来执行shell脚本的,在bash/sh命令下,脚本文件可以无"执行权限",即 ...

  5. 常用判断重复记录的SQL语句

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from people where peopleId in (select   peopleId  fro ...

  6. LeetCode算法题-Minimum Depth of Binary Tree(Java实现)

    这是悦乐书的第168次更新,第170篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第27题(顺位题号是111).给定二叉树,找到它的最小深度.最小深度是沿从根节点到最近的 ...

  7. Linux 小知识翻译 - 「虚拟化技术 续」

    这次,继续聊聊「虚拟化技术」. 根据上回的介绍,虚拟化技术可以使「计算机的台数和运行的OS的个数的比例不再是1:1」.这回介绍一下如何使用这个技术. 使用方法之一,「一台计算机上运行多个OS」.从个人 ...

  8. 设计模式のMediatorPattern(中介者模式)----行为模式

    一.产生背景 从生活中的例子可以看出,不论是QQ游戏还是QQ群,它们都是充当一个中间平台,QQ用户可以登录这个中间平台与其他QQ用户进行交流,如果没有这些中间平台,我们如果想与朋友进行聊天的话,可能就 ...

  9. @RequestParam 和@RequestBody 的区别?

    @RequestParam用来接收: 1 用来处理简单的参数绑定 2 用来接收 Content-Type 是   application/x-www-form-urlencoded (这种格 式的数据 ...

  10. P1433 吃奶酪(搜索DFS+记忆化)

    emmmmm,我还是看了题解的....尴尬,其实不用记忆化搜索也是可以的.因为我不用也是最后一个点超时.但是我是用的贪心+DFS...超时的原因是贪心....mmp,本来加贪心就是为了不超时.... ...