B - School Marks
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Input
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.
Output
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.
Sample Input
Input5 3 5 18 4
3 5 4Output4 1Input5 3 5 16 4
5 5 5Output-1Hint
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个数字,已知k个,所有数字不大于p,求剩余未知数字使数字总和不大于x且中位数不小于y。
按y将已知的k个数字分为左和右两边,再在两侧添加n-k个数字,左侧添1,右侧添y以保证总和尽可能的小。
附AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int n,k,p,x,y,xx,mid;
int a[],ans[]; int main(){
while(cin>>n>>k>>p>>x>>y){
memset(a,,sizeof(a));
memset(ans,,sizeof(ans));
int sum=,cnt=;
int l=,r=;
for(int i=;i<k;i++){//划分左右
cin>>a[i];
sum+=a[i];
if(a[i]<y)
l++;
else if(a[i]>=y)
r++;
}
mid=n/+;
if(l>=mid){//"=" 当左边数目大于或等于一半+1时,中位数不可能为>=y
cout<<"-1"<<endl;
continue;
}
if(r<=mid){//下方第二组数据时不判定的话xx会为负数。。
xx=mid-r;//右侧个数
while(xx--){//取右侧最小值y
ans[cnt++]=y;
sum+=y;
}
} xx=n-r-l-cnt;//剩余数量
while(xx--){//取左侧最小值1
ans[cnt++]=;
sum++;
}
if(sum>x){//大于x时同样不符合要求
cout<<"-1"<<endl;
continue;
}
else{
cout<<ans[];//保证输出格式
for(int i=;i<cnt;i++){
cout<<" "<<ans[i];
}
cout<<endl;
}
}
return ;
}
/*
5 3 5 25 4
3 3 3
*/
/*
9 7 2 13 1
2 2 2 1 1 2 2
*/
B - School Marks的更多相关文章
- 【BZOJ-2400】Spoj839Optimal Marks 最小割 + DFS
2400: Spoj 839 Optimal Marks Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 567 Solved: 202[Submit ...
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 839. Optimal Marks - SPOJ
You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...
- (CodeForces )540B School Marks 贪心 (中位数)
Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, b ...
- 图论(网络流):SPOJ OPTM - Optimal Marks
OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...
- CodeForces 540B School Marks(思维)
B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 【SPOJ839】Optimal Marks 网络流
You are given an undirected graph G(V, E). Each vertex has a mark which is an integer from the range ...
- The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
1 Preface DB Query Analyzer is presented by Master Gen feng, Ma from Chinese Mainland. It has Eng ...
- Codeforces831C Jury Marks
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- (贪心)School Marks -- codefor -- 540B
http://codeforces.com/problemset/problem/540/B School Marks Little Vova studies programming in an el ...
随机推荐
- 【每日Scrum】第八天(4.29) TD学生助手Sprint2
站立会议 组员 今天 签到 刘铸辉 (组长) 绩效考核 Y 刘静 测试用例书写 测试bug报告 测试详细报告 Y 解凤娇 Y 王洪叶 项目可行性报告 项目开发计划书 需求分析(已完成并发布) Y 胡宝 ...
- php中屏蔽date的错误
php中添加 date_default_timezone_set('asia/shanghai'); 可以屏蔽 <?php echo date('Y-m-d',$row3['time']); ...
- CentOS安装配置
1.准备安装 1.1 系统简介 CentOS 是什么? CentOS是一个基于Red Hat 企业级 Linux 提供的可自由使用的源代码企业级的 Linux 发行版本.每个版本的 CentOS 都会 ...
- SQL Cursor生命周期
阅读导航 1 Cursor Step 1.1 Create cursor 1.2 Parse statement 1.3 descript and define 1.4 Bind variable ...
- JAVA RMI远程方法调用简单实例(转载)
来源:http://www.cnblogs.com/leslies2/archive/2011/05/20/2051844.html RMI的概念 RMI(Remote Method Invocati ...
- spring2实现定时任务的一种方式
1. 在项目中放入Spring的jar包 2. applicationContext.xml的<beans xmlns>部分,添加context相关内容: <beans xmlns= ...
- cocos2d-js v3新特性
1.游戏对象 使用cc.game单例代替了原有的cc.Application以及cc.AppControl 2.属性风格API 旧的API ...
- C++设计模式实现--策略(Strategy)模式
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/L_Andy/article/details/30489331 一. 举例说明 曾经做了一个程序,程序 ...
- 【LeetCode】Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- seventBus(封装) 一个巧妙的解决vue同级组件通讯的思路
如果在你项目中需要多处用到同级组件通讯,而又不想去写繁琐的vuex,可以参考这个小思路.本人在写项目中琢磨出来的,感觉挺好用,分享一下. 1.在utils文件夹下添加BusEvent.js 注释已经很 ...