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. PCB常用单位转换 mil 英尺

    PCB常用单位转换 mil 英尺 相关常用单位     1mil   = 0.0254mm 100mil = 2.54mm 1英寸   = 1000mil = 2.54cm 1英尺   = 12英寸  ...

  2. Android 短信验证码控件

    Android 短信验证码控件,便于项目中使用统一样式,统一提示改动.个人觉得挺好用的 <span style="font-size:18px;">public cla ...

  3. kubernetes集群管理命令(三)

    系列目录 前面两节我们由浅入深介绍了不少kubernetes管理比较常用的命令.本节我们通过案例讲解一些需要更为复杂的操作才能完成的命令. 选择一个deployment下的所有pod 前面讲到过,ku ...

  4. 利用CH341A编程器刷新BIOS,恢复BIOS,妈妈再也不用担心BIOS刷坏了

    前几天,修电脑主析就捣鼓刷BIOS,结果刷完黑屏开不了机,立刻意识到完了,BIOS刷错了.就从网上查资料,各种方法试了个遍,什么用处都没有.终于功夫不负有心人,找到了编码器,知道了怎么用.下面看看具体 ...

  5. UNIX网络编程卷1 时间获取程序client TCP 使用非堵塞connect

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.当在一个非堵塞的 TCP 套接字(可使用 fcntl 把套接字变成非堵塞的)上调用 co ...

  6. 2018.11.23-day25 面向对象-封装

    1.经典类 2.多态 3.鸭子类型 4.封装

  7. Redis(二)延迟队列

    1.目录 延迟队列 进一步优化 2.延迟队列 package com.redis; import java.lang.reflect.Type; import java.util.Set; impor ...

  8. java使用ftp局域网内多线程上传图片过慢

    多线程ftp上传文件时候,图片上传很慢,调试和查询资料发现主要在:storeFile方法 解决方案如下: FTPClient fc设置setBufferSize 可以根据内存大小适当设置大点的缓冲区: ...

  9. ios怎样在一个UIImageButton的里面加一些自己定义的箭头

    能够採用例如以下方法,写一个函数: -(UIImage*) getOneImageButtonWithArrow{ //tmpView做附控件 UIView *tmpView = [[UIView a ...

  10. access 连接数据库

    前提条件 如果没有安装office的话,需要安装引擎 安装了office就不用安装引擎 连接数据库 Dim plMydb As Microsoft.Office.Interop.Access.Dao. ...