Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 y points (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, n is 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.

Sample Input

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

Hint

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,求剩余未知数字使数字总和不大于x且中位数不小于y。

按y将已知的k个数字分为左和右两边,再在两侧添加n-k个数字,左侧添1,右侧添y以保证总和尽可能的小。

附AC代码:

 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int n,k,p,x,y,xx,mid;
int a[],ans[]; int main(){
while(cin>>n>>k>>p>>x>>y){
memset(a,,sizeof(a));
memset(ans,,sizeof(ans));
int sum=,cnt=;
int l=,r=;
for(int i=;i<k;i++){//划分左右
cin>>a[i];
sum+=a[i];
if(a[i]<y)
l++;
else if(a[i]>=y)
r++;
}
mid=n/+;
if(l>=mid){//"=" 当左边数目大于或等于一半+1时,中位数不可能为>=y
cout<<"-1"<<endl;
continue;
}
if(r<=mid){//下方第二组数据时不判定的话xx会为负数。。
xx=mid-r;//右侧个数
while(xx--){//取右侧最小值y
ans[cnt++]=y;
sum+=y;
}
} xx=n-r-l-cnt;//剩余数量
while(xx--){//取左侧最小值1
ans[cnt++]=;
sum++;
}
if(sum>x){//大于x时同样不符合要求
cout<<"-1"<<endl;
continue;
}
else{
cout<<ans[];//保证输出格式
for(int i=;i<cnt;i++){
cout<<" "<<ans[i];
}
cout<<endl;
}
}
return ;
}
/*
5 3 5 25 4
3 3 3
*/
/*
9 7 2 13 1
2 2 2 1 1 2 2
*/

B - School Marks的更多相关文章

  1. 【BZOJ-2400】Spoj839Optimal Marks 最小割 + DFS

    2400: Spoj 839 Optimal Marks Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 567  Solved: 202[Submit ...

  2. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  3. 839. Optimal Marks - SPOJ

    You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...

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

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

  5. 图论(网络流):SPOJ OPTM - Optimal Marks

    OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...

  6. CodeForces 540B School Marks(思维)

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

  7. 【SPOJ839】Optimal Marks 网络流

    You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...

  8. The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by

      1  Preface DB Query Analyzer is presented by Master Gen feng, Ma from Chinese Mainland. It has Eng ...

  9. Codeforces831C Jury Marks

    C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  10. (贪心)School Marks -- codefor -- 540B

    http://codeforces.com/problemset/problem/540/B School Marks Little Vova studies programming in an el ...

随机推荐

  1. vim 宏的使用

    1. 基本使用 q[a-z] 开始录制宏 q  停止录制 @[a-z] 使用宏 @@ 调用最近使用的宏 22@[a-z] 多次重放宏 2. 宏的执行方式 串行方式:5@[a-z] 宏内包含向下一个目标 ...

  2. 内核顶层Makefile相关1

    http://www.groad.net/bbs/simple/?f104.htm $(Q) 变量 内核 Makefile 文件 238 行到 259 行的注释中知道,$(Q) 变量的作用是决定是否在 ...

  3. beifen---http://vdisk.weibo.com/s/uhCtnyUhD0Ooc

  4. Linux高端内存

    Linux高端内存是针对物理内存来说的,虚拟内存没有高端这个概念.Linux系统将虚拟内存分为两个部分,即用户地 址空间和内核地址空间,对于32位系统来说,虚拟地址空间为4GB,其中用户空间范围为0- ...

  5. mysql查询结果自动生成序列号

  6. iOS9新特性之新添加的关键字

    iOS9 新出的关键字:用来修饰属性,或者方法的参数,返回值 好处:1.迎合swift 2.提高我们开发人员开发规范,减少程序员之间的交流 注意:iOS9新出的的关键字nonnull,nullable ...

  7. Linux学习笔记--ps命令(显示当前进程的命令)

    ps:英文名process,进程的意思. 1. 命令格式: ps [选项] 2. 经常使用选项: "ps -a" 显示一个终端的全部进程.除了会话引线 "ps -e&qu ...

  8. 九度OJ 1095:2的幂次方 (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:913 解决:626 题目描述: Every positive number can be presented by the exponent ...

  9. 动态绑定允许我们在程序运行的过程中动态给class加上功能,这在静态语言中很难实现

    https://www.liaoxuefeng.com/wiki/ # 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法, # 这就是动态语言的 ...

  10. Android笔记之为TextView设置边框

    效果图 text_view_background.xml <?xml version="1.0" encoding="utf-8"?> <sh ...