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个评委要依次对 ...
随机推荐
- 来自AJPFX的二分法查找
package com.heima.array; public class Demo2_Array { /** * * A:案例演示 * ...
- 原生开发之css样式问题(持续更新)
·移动端开发将div高度设置为设备高度 div{ Height:100vh; } · select选择器文字设置: /*select文字右对齐*/ select{ direction: rtl; } ...
- linux centos 下php的mcrypt扩展
去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包 libmcrypt(libmcrypt-2.5.8.tar.gz ):mcrypt(mcr ...
- 【译】x86程序员手册37-第10章 初始化
Chapter 10 Initialization 第10章 初始化 After a signal on the RESET pin, certain registers of the 80386 a ...
- leetcode_238. Product of Array Except Self_思维
https://leetcode.com/problems/product-of-array-except-self/ 给一个vector<int> nums,输出一个vector< ...
- CREATE CONVERSION - 定义一个用户定义的码制转换
SYNOPSIS CREATE [DEFAULT] CONVERSION name FOR source_encoding TO dest_encoding FROM funcname DESCRIP ...
- 将Jar安装到本地仓库和Jar上传到私服
举例 1. 依赖如下: <dependency> <groupId>org.quartz-scheduler.internal</groupId> <arti ...
- docker数据卷的管理和使用
数据卷的使用,数据库可以保证如果容器出现问题但是数据不丢失的作用,比如MySQL/date下的数据 或者Nginx根目录下的index.html 查看数据卷 [root@docker ~]# dock ...
- Linux网络配置出现的问题
网络连接 : 选择桥接模式进入字符界面后,管理员登入后 ifconfig显示eth0和ol,但是不显示静态IP地址,即无inet.地址.广播.掩码 解决方案: 1.使用sudo dhclient e ...
- crm项目之stark组件前戏(二)
stark组件的设计主要来源于django中admin的功能,在django admin中只需要将模型表进行注册,就可以在页面对该表进行curd的动作,那么django admin是如何做的呢? 在d ...