School Marks-CodeForces
2 seconds
256 megabytes
standard input
standard output
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.
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.
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.
5 3 5 18 4
3 5 4
4 1
5 3 5 16 4
5 5 5
-1
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是n次测试
k是已经考试了k 次
p是最高分数(这题中没有用)
x是n次总成绩的总和
y是这几次成绩的中数
求在剩下的几次测试中,vova都应该考多少分才能满足x和y.(随意的序列都可以)
分析:
根据题目中所说的 至少有(n+1)/2次要>=y
所以我们就先补y然后剩下的全部是1 这样加起来是最小的 如果他还是大与x说明不能满足
如果把剩下的都补成y还是不够(n+1)/2的话也是不能满足的。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue> using namespace std;
#define N 1050
int main()
{
int n,k,p,x,y,a[N],i;
while(scanf("%d %d %d %d %d",&n,&k,&p,&x,&y)!=EOF)
{
int Y=,sum=;
for(i=;i<=k;i++)
{
scanf("%d",&a[i]);
if(a[i]>=y)
Y++;
sum+=a[i];
}
Y=(n+)/-Y;
if(Y<=)
Y=;
int X=n-Y-k;
if(X<=)
X=;
if((sum+Y*y+X)>x || Y>(n-k))
{
printf("-1\n");
}
else
{
for(i=;i<Y;i++)
printf("%d%c",y,(x== && i==y-)?'\n':' ');
for(i=;i<X;i++)
printf("1%c",i==X-?'\n':' ');
}
}
return ;
}
School Marks-CodeForces的更多相关文章
- 2021.5.22 vj补题
A - Marks CodeForces - 152A 题意:给出一个学生人数n,每个学生的m个学科成绩(成绩从1到9)没有空格排列给出.在每科中都有成绩最好的人或者并列,求出最好成绩的人数 思路:求 ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- CodeForces 540B School Marks
http://codeforces.com/problemset/problem/540/B School Marks Time Limit:2000MS Memory Limit:26214 ...
- 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 ...
- codeforces 540B.School Marks 解题报告
题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test ...
- (CodeForces )540B School Marks 贪心 (中位数)
Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, b ...
- CodeForces 540B School Marks(思维)
B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- CodeForces - 540B School Marks —— 贪心
题目链接:https://vjudge.net/contest/226823#problem/B Little Vova studies programming in an elite school. ...
- 【Codeforces Round #424 (Div. 2) C】Jury Marks
[Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...
随机推荐
- ES之事件绑定,解除绑定以及事件冒泡、事件捕获
绑定事件的处理方法任何元素都有事件属性,而绑定事件就是将这个事件与一个函数相连接. ①句柄事件dom.onXXX = function () {代码块} 以on开头的事件属于句柄事件兼容性非常好,但是 ...
- iOS 蓝牙的GameKit用法
一.连接蓝牙 显示可以连接的蓝牙设备列表 - (IBAction)buildConnect:(id)sender { // 创建弹窗 GKPeerPickerController *ppc = [[G ...
- H.264学习笔记4——变换量化
A.变换量化过程总体介绍 经过帧内(16x16和4x4亮度.8x8色度)和帧间(4x4~16x16亮度.4x4~8x8色度)像素块预测之后,得到预测块的残差,为了压缩残差信息的统计冗余,需要对残差数据 ...
- JavaScript——blob、file、flieReader、createObjectURL
https://blog.csdn.net/opengl_es/article/details/44336477 https://www.cnblogs.com/hhhyaaon/p/5928152. ...
- vuex的应用和解决的实际问题
这是vuex的语法结构内容 简单的理解vuex: new Vue({ // state data () { return { count: 0 } }, // view template: ` < ...
- CSS中常用属性之字体属性
1,以下是CSS中常用字体属性: font-family 字体样式 font-size 字体大小 font-size-adjust 为元素规定 ...
- nutwk的maven中央仓库及配置
官方maven服务器:https://jfrog.nutz.cn/artifactory/jcenter/ 如果用阿里的maven服务器,特别提醒:
- CAD参数绘制椭圆(网页版)
在CAD设计时,需要绘制椭圆,用户可以设置椭圆的基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipse 绘制椭圆.详细说明如下: 参数 说明 DOUBLE dCenterX 椭圆 ...
- DEBUG无法进入断点解决方法
18/08/17 任务栏:Tools->Options->Debugging->General->Require source files to exactly match t ...
- 10C++类和对象
类和对象 8.1 面向对象程序设计方法概述 到目前为止,我们介绍的是C++在面向过程的程序设计中的应用.对于规模比较小的程序,编程者可以直接编写出一个面向过程的程序,详细地描述每一瞬时的数据结构及对其 ...