题意:一共n个数,给出其中k个数,要求这n个数的中位数为y,这n个数的和不超过x,补全剩下的n-k个数

先统计给出的k个数里面比中位数小的数,

如果cnt<=n/2,说明中位数还没有出现,把这n/2-cnt个数都补上1,剩下的都补上y

如果cnt>n/2,说明中位数不存在

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn]; int main(){
int n,k,p,x,y;
cin>>n>>k>>p>>x>>y;
int ans=;
int sum=;
for(int i=;i<=k;i++){
cin>>a[i];
sum+=a[i];
if(a[i]<y) ans++;
}
int l,r; if(ans<=n/){
l=min(n/-ans,n-k);
r=n-l-k;
sum+=l+r*y; if(sum>x) printf("-1\n");
else{
for(int i=;i<=l;i++) printf("1 ");
for(int i=;i<=r;i++) printf("%d ",y);
printf("\n");
}
}
else printf("-1\n");
return ;
}

g0---oooooooooo

codeforces 540 B School Marks【贪心】的更多相关文章

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  3. (CodeForces )540B School Marks 贪心 (中位数)

    Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, b ...

  4. CodeForces - 540B School Marks —— 贪心

    题目链接:https://vjudge.net/contest/226823#problem/B Little Vova studies programming in an elite school. ...

  5. CodeForces 540

    A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  7. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  8. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

  9. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

随机推荐

  1. vue 初始化项目模板报错

    E:\xiaogezi.cn\vue>vue init webpack myProject vue-cli · Failed to download repo vuejs-templates/w ...

  2. Java中如何使用线程

    首先了解线程的状态转换图: 在Java中一个类要当做线程来使用有两种方法: 1)继承Thread类,并重写run函数 2)实现Runnable接口,并重写run函数 Java是单继承的,但某些情况下一 ...

  3. 【转载】犀利的 oracle 注入技术

    介绍一个在web上通过oracle注入直接取得主机cmdshell的方法. 以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTEN ...

  4. javascript常用代码(不完整版)

    求大神指点 Javascript嵌入式 <script typt:javascript>代码</script> 注释 //或者/*内容*/ 变量名赋值 Var 变量名 = 值 ...

  5. 3ds Max做的卡通狗教程

    使用软件::3ds Max 软件下载:http://www.xy3dsmax.com/xiazai.html 全教程完,学完记得交作业.如果本教程对您有所帮助,请推荐给你的朋友.

  6. 通过唯一ID实现简单的日志跟踪实现

    在实际项目中,通知我们需要记录一些日志,方便问题核查.但是日志多了就很容易混乱,请求,响应,执行中的日志无法对应,这时就需要为请求进行标记唯一ID来进行跟踪. /** * 记录请求日志 * * Cla ...

  7. Camera Calibration 相机标定:原理简介(二)

    2 针孔相机模型 常见的相机标定中,使用的相机多为针孔相机(Pinhole camera),也就是大家熟知的小孔成像理论.将其中涉及的坐标系之间的相互转换抽离出来,即为针孔相机模型的核心. 上图所示的 ...

  8. 配置oh-my-zsh

    1. 当使用zsh进入庞大的git工程目录下时,会发生cd命令很慢的情况 可以把~/.oh-my-zsh/lib/git.zsh里面的git_prompt_info函数替换为 function git ...

  9. HDU——T 2444 The Accomodation of Students

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

  10. 使用Qt.labs.settings来存储应用的设置

    我在曾经的文章中,讲述了怎样使用U1db及SQLite offline storage API来存储应用的一些状态.在这篇文章中,我将介绍怎样使用Qt.labs.settings来存储应用的状态.更加 ...