题目传送门

 /*
贪心:首先要注意,y是中位数的要求;先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数
num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //Codeforces Round #301 (Div. 2) B. School Marks
{
//freopen ("B.in", "r", stdin); int n, k, p, x, y;
while (scanf ("%d%d%d%d%d", &n, &k, &p, &x, &y) == )
{
int sum = , cnt = ;
for (int i=; i<=k; ++i)
{
scanf ("%d", &a[i]); sum += a[i];
if (a[i] < y) cnt++;
} if (cnt <= n / )
{
int num1 = min (n / - cnt, n - k);
int numy = n - k - num1; sum += num1 + numy * y;
if (sum > x) puts ("-1");
else
{
for (int i=; i<=num1; ++i) printf ("%d%c", , (numy== && i==num1) ? '\n' : ' ');
for (int i=; i<=numy; ++i) printf ("%d%c", y, (i==numy) ? '\n' : ' ');
}
}
else puts ("-1");
} return ;
}

贪心 Codeforces Round #301 (Div. 2) B. School Marks的更多相关文章

  1. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

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

    B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/probl ...

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

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

  4. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  5. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

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

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  7. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  8. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  9. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

随机推荐

  1. 整理的dedecms标签大全,方便查找

    平时用dedecms开发经常会用到一些标签,特别是首页.栏目页.内容页,这些页面都会用到标签的调用,比如title.keywords.description.arclist.field.body等,为 ...

  2. PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数详解

    求两个数组的交集问题可以使用 array_intersect(),array_inersect_assoc,array_intersect_key来实现,其中 array_intersect()函数是 ...

  3. Nginx反向代理 负载均衡

    nginx 这个轻量级.高性能的 web server 主要可以干两件事情: 〉直接作为http server(代替apache,对PHP需要FastCGI处理器支持): 〉另外一个功能就是作为反向代 ...

  4. 在mac上安装nodejs

    文章转载自我的个人博客  www.iwangzheng.com node.js最初是2009年发布的,目标是为聊实现事件驱动和非阻塞I/O的web服务器,应用的场景非常的广泛,有web服务器.实时应用 ...

  5. wordpress工作原理

    WP初始化的过程:当你输入<yourlink>/wordpress对wordpress进行初始化时,wordpress默认会找根目录下的index.php页面,看一下index.php页面 ...

  6. What is the difference between provider network and self-service network in OpenStack?

    "self-service networking" allows users to create their own virtual networks, subnets, rout ...

  7. .html和.htm的区别

    很多人会认为网页扩展名html和htm是等同的,但事实上他们还是有区别的. 包含HTML内容的文件最常用的扩展名是.html,但是像DOS这样的旧操作系统限制扩展名为最多3个字符,所以.htm扩展名也 ...

  8. for循环,pydev提示未使用的变量,解决办法

    对于如下代码,pvdev会产生未使用变量的警告 for i in range(5): func() 解决办法: 把变量替换成下划线_,就不会生产告警了.改变后如下: for _ in range(5) ...

  9. iOS 定制controller过渡动画 ViewController Custom Transition使用体会

    最近学习了一下ios7比较重要的一项功能,就是 controller 的 custom transition. 在ios7中,navigation controller 中就使用了交互式过渡来返回上级 ...

  10. 转mysql复制主从集群搭建

    最近搭了个主从复制,中间出了点小问题,排查搞定,记录下来 1环境:虚拟机:OS:centos6.5Linux host2 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 ...