题目传送门

 /*
贪心:首先要注意,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. Hadoop之伪分布环境搭建

    搭建伪分布环境 上传hadoop2.7.0编译后的包并解压到/zzy目录下 mkdir /zzy 解压 tar -zxvf hadoop.2.7.0.tar.gz -C /zzy     配置hado ...

  2. 解决 MySQL Cluster 通过 某一个MySqld节点新建表时,其他 MySqld节点 看不到表内容的问题

    问题: 总共有 4 个MySqld节点,通过其中的一个节点新建表时,发现其他 MySqld节点 查不到表内容的问题,即表没有同步过来. 解决方案: 主要是因为新建表时,所选的 表引擎 错误导致的,只能 ...

  3. Windows主机里利用VMware安装Linux(CentOS)虚拟机,Host-only连接上网方式详解

    关于Host-only指的是主机与虚拟机之间的互联,因此虚拟机是不能连网的,若需要连网则需要使用NAT模式: Host-only模式实现联网得考虑如下配置过程: 附:VMware虚拟机三种网络模式(B ...

  4. Loadrunner日志设置与查看

    1.打开EXtended Log Log告诉了我们一切,默认的Log是standard Log,这时远远不够的.我们要extended log,打开路径为runtime settings-->l ...

  5. ios图标和默认图像

    Icon.png和Default.png是两个重要的图像文件.Icon.png充当应用程序的图标,这些图标用于在SpringBoard主屏幕上表示应用程序.Default.png(也称"启动 ...

  6. 【Spring】Spring系列6之Spring整合Hibernate

    6.Spring整合Hibernate 6.1.准备工作 6.2.示例 com.xcloud.entities.book com.xcloud.dao.book com.xcloud.service. ...

  7. Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. Notice The minimu ...

  8. HTML模仿桌面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. swift 中String,Int 等类型使用注意,整理中

    swfit中的String和Int是 struct定义的,不同于NSString和NSNumber, 如果想在一个数组中同时包含String和Int,那么这个数组要声明为[Any] 而不是 [AnyO ...

  10. Java入门学习知识点汇总

    Java入门重要知识点在这里总结一下,以方便日后复习,这部分内容主要有:变量和常量,常用的运算符,流程控制语句,数组,方法这些内容 一.变量和常量 1.Java关键字 先贴张图: 所有关键字区分大小写 ...