题目链接:https://vjudge.net/contest/226823#problem/B

Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart he is and start distracting him asking to let them copy his homework. And if the median of his marks will be lower than ypoints (the definition of a median is given in the notes), then his mom will decide that he gets too many bad marks and forbid him to play computer games.

Vova has already wrote k tests and got marks a1, ..., ak. He doesn't want to get into the first or the second situation described above and now he needs to determine which marks he needs to get for the remaining tests. Help him do that.

Input

The first line contains 5 space-separated integers: nkpx and y (1 ≤ n ≤ 999, nis odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total number of points so that the classmates don't yet disturb Vova, y is the minimum median point so that mom still lets him play computer games.

The second line contains k space-separated integers: a1, ..., ak (1 ≤ ai ≤ p) — the marks that Vova got for the tests he has already written.

Output

If Vova cannot achieve the desired result, print "-1".

Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.

Examples

Input
5 3 5 18 4
3 5 4
Output
4 1
Input
5 3 5 16 4
5 5 5
Output
-1

Note

The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai.

In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the median point of the sequence {1, 3, 4, 4, 5} equals to 4, that isn't less than 4, so his mom lets him play computer games.

Please note that you do not have to maximize the sum of marks or the median mark. Any of the answers: "4 2", "2 4", "5 1", "1 5", "4 1", "1 4" for the first test is correct.

In the second sample Vova got three '5' marks, so even if he gets two '1' marks, the sum of marks will be 17, that is more than the required value of 16. So, the answer to this test is "-1".

题意:

有n个数,已知其中k个,且所有数的大小都不超过p且不小于1。问是否有这样一组数,满足:他们的和不超过x,中位数不小于y?

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long LL;
const double eps = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e5+; int n, k, p, x, y, a[MAXN];
int main()
{
while(cin>>n>>k>>p>>x>>y)
{
int left = x;
for(int i = ; i<=k; i++)
scanf("%d",&a[i]), left -= a[i]; sort(a+,a++k); //对已有的数进行排序
int mid = (n+)/; //中位数的下标
int pos = lower_bound(a+,a++k,y)-(a+); //求出比y小的最大的数的下标(亦是个数)
if(pos>=mid) //如果下标达到或超过了中位数的下标,则必定满足不了条件
left = -;
else //没有达到中位数的下标,则继续
{
int cnt = mid--pos; //为了尽可能保留left,在中位数之前的剩余空位全部放1
for(int i = k+; i<=k+cnt&&i<=n; i++)
a[i] = , left -= ;
for(int i = k+cnt+; i<=n; i++) //中位数以及剩余的为全部放y。
a[i] = y, left -= y;
} if(left<)
puts("-1");
else
{
for(int i = k+; i<=n; i++)
printf("%d ", a[i]);
puts("");
}
}
}

CodeForces - 540B School Marks —— 贪心的更多相关文章

  1. (CodeForces )540B School Marks 贪心 (中位数)

    Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, b ...

  2. CodeForces 540B School Marks

    http://codeforces.com/problemset/problem/540/B School Marks Time Limit:2000MS     Memory Limit:26214 ...

  3. CodeForces 540B School Marks (贪心)

    题意:先给定5个数,n,  k, p, x, y.分别表示 一共有 n 个成绩,并且已经给定了 k 个,每门成绩 大于0 小于等于p,成绩总和小于等于x, 但中位数大于等于y.让你找出另外的n-k个成 ...

  4. codeforces 540B.School Marks 解题报告

    题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test ...

  5. CodeForces 540B School Marks(思维)

    B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  6. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  7. CodeForces - 50A Domino piling (贪心+递归)

    CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...

  8. Codeforces 161 B. Discounts (贪心)

    题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...

  9. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

随机推荐

  1. 微信小程序 - 单个题目

    后端传过来的数据,如果通过wx:for遍历出来那就是一个页面全部排下来.... 我的想法就是,页面初始化时设置一个默认值 1/50 就是 index+1 / 50(后端传过来的数组长度),通过控制in ...

  2. layui-概念-入门-总结

    layui教程:http://www.dosrun.com/layui/ 获得 Layui你可以在官网首页下载到 Layui 的最新版,也可以通过 GitHub得到Layui的开源包.目前只同步维护这 ...

  3. C#中回调函数的使用方法和区别

    归纳来说有两种方式,一种是委托型回调,另一种是接口型回调 委托型回调 委托型回调包括纯委托型和事件型,他们的实现方式是通过公开成员注入的方式,其中纯委托型还可以用构造函数注入.方法注入的方式 接口型回 ...

  4. Html5 meta 笔记

    摘抄:原文地址:http://www.kmapk.com/html/help/02/127.html 一.天猫 <title>天猫触屏版</title> <meta co ...

  5. jQuery--基础(查询标签)

    浅谈jQuery使用背景 jQuery是使用原生js写成的一个库,使用简单,提高开发效率.在用js冗杂的代码解决的问题中,大部分都可以用jQuery来快速解决. 例如: js中查询网页中ID为&quo ...

  6. HTML5之Canvas绘图(一) ——基础篇

    HTML5火的正热,最近有个想法也是要用到HTML的相关功能,所以也要好好学习一把. 好好看了一下Canvas的功能,感觉HTML5在客户端交互的功能性越来越强了,今天看了一下Canvas绘图,下边是 ...

  7. linux下安装redis报错问题。

    1.使用tar -xzvf redis-2.4.5.tar.gz来解压安装包 2.使用make命令来编译Redis 如果出现错误需要查看是否缺少gcc gcc-c++ zmalloc.h:50:31: ...

  8. 自制小工具大大加速MySQL SQL语句优化(附源码)

    引言 优化SQL,是DBA常见的工作之一.如何高效.快速地优化一条语句,是每个DBA经常要面对的一个问题.在日常的优化工作中,我发现有很多操作是在优化过程中必不可少的步骤.然而这些步骤重复性的执行,又 ...

  9. Anaconda2

    Anaconda 是一个打包的python,一次把好多需要的包都安装好了.对于Python2.7把PyQt5都弄好了,不需要自己来编译! 看看这个 http://conda.pydata.org/do ...

  10. 【问】Windows下C++局部变量在内存中的分布问题

    原本是为了看看C++对象模型中子对象赋值给一个父对象和父类型指针指向的域时,到底会不会切割,就打开codebloks写了下面的代码,编译器选的是GNU. #define DEBUG(X) std::c ...