Codeforce 540B School Marks (贪心)No.6

School Marks

传送
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: n, k, p, x 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.

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”.


题目大意:

绫小路清隆是个默默无闻的大神,他每次考试都能控制自己的分数1~p。一学期一共n次考试,已经考了k次。他如果总分超过x那他就会被同学关注,如果他所有考试成绩的中位数小于y,那他就会被他妈谈人生。路哥想一直保持默默无闻,请问他剩下的考试应该考多少分?(给出一种解,无解输出-1)

做法:

在保证中位数不低于y的情况下尽可能的考1分
所以当中位数小于y时考y分
当中位数大于等于y时考1分
最后判断合法性
不合法输出-1

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,p,x,y,sum,cnt;
int a[10010],ans[10010];
int read(){
int res=0,w=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-') ch=getchar();
if(ch=='-') w=-1,ch=getchar();
while(isdigit(ch)) res=res*10+ch-'0',ch=getchar();
return res*w;
}
int main(){
n=read();k=read();p=read();x=read();y=read();
for(int i=1;i<=k;i++){
a[i]=read();
sum+=a[i];
}
sort(a+1,a+1+k);
for(int i=k+1;i<=n;i++){
if(a[i/2]>=y){
ans[++cnt]=1;
a[i]=1;
sum+=1;
}
else{
ans[++cnt]=y;
a[i]=y;
sum+=y;
}
sort(a+1,a+1+i);
}
if(sum>x||a[n/2+1]<y){
cout<<"-1"<<" ";
}
else{
for(int i=1;i<=cnt;i++){
cout<<ans[i]<<" ";
}
}
return 0;
}

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2018 Gilgamesh All Rights Reserved.

UV : | PV :