CodeForces 540B School Marks

http://codeforces.com/problemset/problem/540/B

School Marks

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 540B

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: nkpx 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

Input

5 3 5 18 43 5 4

Output

4 1

Input

5 3 5 16 45 5 5

Output

-1

Hint

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道题,每道题的分值是1到p, Vova已经写了k道题, (1)Vova获得的总分数不能超过x,(2)中间的分数(即第(n+1)/2个分数(其中得到的所有的分数都是排过序的))不能超过y,问 Vova能否做到

不能做到输出-1,否则输出剩下n-k道题的得分

既然中间分数不能超过y,那么我们就假设中间分数就是y,先让 Vova的分数满足(2), 那么接下来我们就要在保证中间数为y的前提下尽可能得使总分数小,

那么我们可以让中间数前面(中间数前面的得分必须比y要小,这样才能保证y是中间数)空着的地方得分为1,中间数后面空着的地方的得分为y,然后再判断总

分是否比x小

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<algorithm>

using namespace std;
const int N = 1010;
typedef __int64 ll;

int main()
{
    int n, k, p, x, y, num;
    while(~scanf("%d%d%d%d%d", &n, &k, &p, &x, &y))
    {
        int m = 0, sum = 0;
        for(int i = 0 ;i < k ; i++)
        {
            scanf("%d", &num);
            sum += num;
            if(num < y)
                m++;//m统计比中间数y小的数的个数
        }
        if(m > n / 2)
        {
            printf("-1\n");
            continue;
        }
        int t1 = min(n - k, n / 2 - m);//中间数前面还有多少个空位来放1
        int t2 = n - k - t1;//中间数后面还有多少个空位来放y
        int sum2 = sum + t1 * 1 + t2 * y;//所得的总分数
        if(sum2 > x)
            printf("-1\n");
        else
        {
            for(int i = 0 ; i < t1 ; i++)
                printf("1 ");
            for(int i = 0 ; i < t2 ; i++)
                printf("%d ", y);
            printf("\n");
        }
    }
    return 0;
}
/*
9 7 2 14 1
2 2 2 1 1 2 2
*/
时间: 2024-10-07 19:40:59

CodeForces 540B School Marks的相关文章

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

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 st

CodeForces 540B School Marks (贪心)

题意:先给定5个数,n,  k, p, x, y.分别表示 一共有 n 个成绩,并且已经给定了 k 个,每门成绩 大于0 小于等于p,成绩总和小于等于x, 但中位数大于等于y.让你找出另外的n-k个成绩. 析:利用贪心算法,首先是只能小于等于 p,也就是成绩越小越好, 然后中位数还得大于等于y,所以我们放的成绩只有两个,一个是1,另一个是y,那么是最优的, 所以每次只要判定这个就好,在判定的时候,要先排序,再找中位数,再就是每次放两个,如果n-k不是偶数,那么就放一个数,再进行. 代码如下: #

cf 540b School Marks 贪心

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

CodeForces - 831C Jury marks

Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added

「日常训练」School Marks(Codeforces Round 301 Div.2 B)

题意与分析(CodeForces 540B) 代码 #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset((x), 0, sizeof(x)) #define

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

贪心 Codeforces Round #301 (Div. 2) B. School Marks

题目传送门 1 /* 2 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 3 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 using na

Codeforces 831C--Jury Marks (暴力)

题目链接:http://codeforces.com/problemset/problem/831/C 题意:有一位参赛选手,我们不知道他初始或最后的成绩,但是知道k次评审所加(减)的分数,以及n个在这过程中的他的分数.问这名选手初始分有几种情况. 思路:一开始考虑先求出评审分的前缀和,对过程分减去前缀和就能得到的初始分数,求出所有的初始分数情况,用map记录每个初始分重复的次数,重复次数==n 的即为正确的初始分. 然而这么做是WA了的. 分析第一个样例: 4 1-5 5 0 2010 如果按

540B :School Marks

题目链接 题意: 输入: 第一个: n k p x y 第二行:k个数 n: 数的数量 k:n个数中已经知道的k个数 p:n个数取值的上界,下界是1 x:n个数的和的上界x y:n个数的中位数至少是 y 输出: 补充其余的n-k个数,使得这个n个数的和不大于x,中位数不小于y 解题思想: 对已经知道的k个数,判断其中大于等于y的数median有几个, 若median<=n/2 说明已知道的k个数中大于y的不到一半,则在未知道的n-k个数中,补充y,当median>n/2 时候停止 若还没有补充