B. School Marks

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/540/problem/B

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

Sample Input

5 3 5 18 4
3 5 4

Sample Output

4 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科,他需要他的n科分数和不大于x,中位数不小于y

然后让你构造出一个可行解

题解:

把剩下的n-k科全部置为y,如果不行,就置为1

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
/*inline void P(int x)
{Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts("");
}
*/
inline ll read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
inline void P(int x)
{Num=0;if(!x){putchar('0');puts("");return;}while(x>0)CH[++Num]=x%10,x/=10;while(Num)putchar(CH[Num--]+48);puts("");
}
//**************************************************************************************int a[maxn];
int main()
{int n,k,p,x,y;cin>>n>>k>>p>>x>>y;for(int i=1;i<=k;i++)a[i]=read(),x-=a[i];for(int i=k+1;i<=n;i++){x-=1;a[i]=1;}if(x<0){puts("-1");return 0;}for(int i=k+1;i<=n;i++){int d=min(x,y-1);x-=d;a[i]+=d;}int ans=0;for(int i=1;i<=n;i++){if(a[i]>=y)ans++;}if(ans>=(n/2)+1){for(int i=k+1;i<=n;i++)cout<<a[i]<<" ";return 0;}puts("-1");
}

转载于:https://www.cnblogs.com/qscqesze/p/4470263.html

Codeforces Round #301 (Div. 2) B. School Marks 构造/贪心相关推荐

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

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

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

    其实是很水的一道bfs题,昨晚比赛的时候没看清题意,漏了一个条件. 1 #include<cstdio> 2 #include<cstring> 3 #include<i ...

  3. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  4. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MB Submit: xxx ...

  5. Codeforces Round #742 (Div. 2) F. One-Four Overload 构造 + 二分图染色

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗mn*mn∗m的矩形,包含...和XXX,你有两种颜色,你需要给...染色使得每个XXX上下左右相邻的...其两种颜色个数相同,输出一种合法方案. ...

  6. Codeforces Round #740 (Div. 2) E. Bottom-Tier Reversals 构造

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为奇数nnn的排列aaa,每次可以选择长度为奇数的前缀,并将[1,len][1,len][1,len]翻转,你需要用不超过5n2\frac{5n} ...

  7. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  8. Codeforces Round #301 (Div. 2) C. Ice Cave BFS

    C. Ice Cave Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/C ...

  9. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

最新文章

  1. Kafka原理和实践--云平台技术栈13
  2. 浅谈 ThreadLocal
  3. apue对java_[apue] 一个快速确定新系统上各类限制值的工具
  4. 开启linux ssh
  5. Cross-Site Scripting(XSS)的类型
  6. Lucene和Solr版本对应关系
  7. I00017 生成9开头的按位递减数
  8. python网络爬虫系列教程——Python+PhantomJS +Selenium组合应用
  9. 判断游戏对象是否在摄像机视口的一个方法
  10. 计算机毕业设计进度计划表,毕业设计 进度计划表
  11. 11-新闻发布系统数据库-新闻数据操作
  12. 开启和关闭Windows远程管理(WinRM)
  13. 哈佛幸福课--部分笔记
  14. EXCEL条件格式小知识:条件判断如何写公式,可多层if
  15. php给发qq消息,PHP 模拟QQ登录及发送消息实现方法
  16. [Android]自定义锁屏并屏蔽按键
  17. 135节---------4月11日
  18. [Games 101] Lecture 06 Rasterization 2 (Antialiasing and Z-Buffering)
  19. 觅伊APP产品体验测评:打造真人社交,得女性者得市场
  20. 青鸟迷你游戏平台:游戏点击率

热门文章

  1. python pow函数用法_Python代码中pow()函数具有哪些功能呢?
  2. 计算机组成原理—存储系统总结
  3. UVA - 699 The Falling Leaves
  4. 试题18 四平方和(枚举法)
  5. bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场(DFS)
  6. HAUT校赛--某科学的打麻将
  7. opencv kmeans聚类 实现图像色彩量化
  8. 日志收集系统Elasticsearch,Fluentd , Kibana
  9. intel 酷睿core系列cpu的类型:U M H HQ MQ
  10. 用友u8采购发票如何取消审核