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. JavaScript插件编写指南

    在编写插件之前,大家要先了解做插件的几个要点: 插件需要满足的条件 一个可复用的插件需要满足以下条件: 插件自身的作用域与用户当前的作用域相互独立,也就是插件内部的私有变量不能影响使用者的环境变量: ...

  2. px rem css 转换工具

    http://520ued.com/tools/rem mark 一下 貌似还挺好用

  3. Spring Boot外部化配置实战解析

    一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...

  4. SecureCRT 7.0 如何自动记录日志

    设置步骤如下: 1.打开SecureCRT ,在菜单里选择“选项”-->“全局选项”    2.然后选择“常规”--> “默认会话”--> “编辑默认设置”    3.然后选择“日志 ...

  5. maven命令学习-发布上传jar包-deploy

    Maven学习六之利用mvn deploy命令上传包 转http://blog.csdn.net/woshixuye/article/details/8133050 mvn:deploy在整合或者发布 ...

  6. 物联网网络编程和web编程

    本文是基于嵌入式物联网研发project师的视觉对网络编程和web编程进行阐述. 对于专注J2EE后端服务开发的同学来说,这篇文章可能略微简单.可是网络编程和web编程对于绝大部分嵌入式物联网proj ...

  7. Struts2 原理(转载)

    图来源于Struts2官方站点,是Struts 2 的整体结构. Struts2框架由3个部分组成:核心控制器FilterDispatcher.业务控制器和用户实现的业务逻辑组件.在这3个部分里,St ...

  8. spring2实现定时任务的一种方式

    1. 在项目中放入Spring的jar包 2. applicationContext.xml的<beans xmlns>部分,添加context相关内容: <beans xmlns= ...

  9. 虚拟机linux安装mysql

    安装mysql时需要的全套安装包 mysql-5.1.73-3.el6_5.i686.rpm mysql-libs-5.1.73-3.el6_5.i686.rpm mysql-server-5.1.7 ...

  10. sap人员编制

    [转]中小SAP项目中的人员编制 转自http://w39.itpub.net/post/24/398817   对于SAP项目来说,常有人把项目所需的人员说的很多--每个模块一个内部顾问和一个开发的 ...