codeforces 540B School Marks
2016-03-08 16:31
197 查看
B. School Marks
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
output
input
output
Note
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,由于Vova不想成绩太突出引起老师们的重视,所以他n场考试总分不能超过x分,而他妈妈对他的要求是,所有考试成绩从小到大排序,处于中间位置的成绩不能低于y分,现给出已考的k门成绩,求其他的成绩,有多种答案,输出任意一种即可。
计数已考的成绩中低于y分的个数cnt,若小于等于pos--(中位数之前的个数)则为min(pos-cnt,n-k)个1 ,其余为y即可。至于前面要选择两个中的较小的,是因为存在一种情况,k比较大而且这k个成绩都大于等于y,那么若再有pos-cnt个1的话总数就会大于n了。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
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.
Examples
input
5 3 5 18 4 3 5 4
output
4 1
input
5 3 5 16 4 5 5 5
output
-1
Note
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,由于Vova不想成绩太突出引起老师们的重视,所以他n场考试总分不能超过x分,而他妈妈对他的要求是,所有考试成绩从小到大排序,处于中间位置的成绩不能低于y分,现给出已考的k门成绩,求其他的成绩,有多种答案,输出任意一种即可。
计数已考的成绩中低于y分的个数cnt,若小于等于pos--(中位数之前的个数)则为min(pos-cnt,n-k)个1 ,其余为y即可。至于前面要选择两个中的较小的,是因为存在一种情况,k比较大而且这k个成绩都大于等于y,那么若再有pos-cnt个1的话总数就会大于n了。
#include <iostream> #include<cstdio> #include<cstring> #include<queue> #include<vector> #include<algorithm> #define maxn 1010 using namespace std; int rr[maxn]; int main() { int n,k,p,x,y,s; while(~scanf("%d%d%d%d%d",&n,&k,&p,&x,&y)) { s=0; memset(rr,0,sizeof(rr)); for(int i=1;i<=k;++i) { scanf("%d",&rr[i]); s+=rr[i]; } int pos=n/2; if(n&1) pos++; s=x-s; if(s<n-k||x<y) { printf("-1\n"); continue; } sort(rr+1,rr+k+1); int cnt=0; for(int i=1;i<=k;++i) { if(rr[i]<y) cnt++; else break; } pos--; int need1=0,need2=0; if(cnt<=pos) { need1=min(pos-cnt,n-k); need2=n-k-need1; } else { printf("-1\n"); continue; } if(need1+need2*y>s) printf("-1\n"); else { if(need1) { printf("1"); need1--; for(int i=0;i<need1;++i) printf(" 1"); for(int i=0;i<need2;++i) printf(" %d",y); printf("\n"); } else { printf("%d",y); need2--; for(int i=0;i<need2;++i) printf(" %d",y); printf("\n"); } } } return 0; }
相关文章推荐
- HDFS源码分析之DataXceiverServer
- AS Gradle 使用笔记
- android存储
- HSV(HSL)颜色空间及其应用
- (转载)Java反射机制
- 跨域请求补充
- .gitignore文件不起作用的解决方法
- UVALive3181(区间DP)
- 顺序容器
- Android studio gradle 配置
- 代码托管服务器比较
- 算法系列(1)排序算法
- 共同学习Java源码--常用数据类型--String(一)
- Android App整体架构设计的思考
- Redis入门很简单之六【Jedis常见操作】
- oracle登录时会报错 initialization error
- Atitit.json xml 序列化循环引用解决方案json
- 万恶DevExpress
- dedecms怎么给第一个li加class
- 记录 yii GridView 默认搜索条件