B. School Marks (CF #301 (Div. 2))

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: 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 test(s)

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个数,先给出p个数,现在要求另外n-p个数,使得这n个数的中位数大于等于y,并且n个数之和不大于x。没有方案就输出-1.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1005
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef long long ll;
using namespace std;

int n,p,k,x,y;
int a[maxn];
int ans[maxn];

int main()
{
//    freopen("C:/Users/asus1/Desktop/IN.txt","r",stdin);
    int i,j;
    while (~scanf("%d%d%d%d%d",&n,&p,&k,&x,&y))
    {
        int s=0,l=0,r=0,num=0,cnt=0;
        for (i=0;i<p;i++)
        {
            scanf("%d",&a[i]);
            s+=a[i];
            if (a[i]<y) l++; //记录比y小的数有多少
            else if (a[i]>=y) r++;//记录大于等于y的数有多少
        }
        if (l>=n/2+1){  //如果比y小的数超过了一半,那么中位数不可能达到y了
            printf("-1\n");
            continue;
        }
        int xx=n/2+1-r;
        while (xx>0){  //填充右边,尽量填y使得和最小
            ans[cnt++]=y;
            xx--;s+=y;
        }
        xx=n-r-l-cnt;
        while (xx>0)    //填充左边,填1使和尽量小
        {
            ans[cnt++]=1;
            xx--;s++;
        }
        if (s>x){   //和超过x输出-1
            printf("-1\n");
            continue;
        }
        printf("%d",ans[0]);
        for (i=1;i<cnt;i++)
            printf(" %d",ans[i]);
        printf("\n");
    }
    return 0;
}
时间: 2024-10-13 16:19:49

B. School Marks (CF #301 (Div. 2))的相关文章

C. Ice Cave (CF #301 (Div. 2) 搜索bfs)

C. Ice Cave time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to

贪心 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 Round #301 (Div. 2) -- (A,B,C,D)

题目传送:Codeforces Round #301 (Div. 2) A. Combination Lock 水题,求最小移动次数,简单贪心一下即可 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #i

CF #371 (Div. 2) C、map标记

1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的匹配. #include<bits/stdc++.h> #define max(a,b) a>b?a:b #define F(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(a)) #define INF

CF#247(Div. 2)部分题解

引言: 在软件项目中,Maven提供了一体化的类库管理系统,非常实用.但是,如果新增的类库jar在网络上无法获取到,如何在本地按照Maven的规则添加进来呢?本文将通过一个小例子展示新增过程. 背景介绍: 一个Maven管理的Java项目,提供一个系统级别的POM.xml,其中定义了整个项目使用的类库. 需求: 需要添加一个自定义的类库到当前项目中.假定当前的类库文件名为:abc.jar.. 如何将类库添加进来? 1.  找到当前Maven的Repository类库位置 一般默认情况下,在win

CF #375 (Div. 2) D. bfs

1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多少个湖,然后输出. #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,s

DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

题目传送门 1 /* 2 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 3 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两点相邻, 4 那么要不就是踩一脚就破了或者踩一脚走开再走回来踩一脚破了:3. 普通的搜索看是否能到达, 5 若能还是要讨论终点踩几脚的问题:) 6 DFS 耗时大,险些超时,可以用BFS来做 7 */ 8 #include <cstdio> 9 #include <algorit

贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

题目传送门 1 /* 2 贪心水题:累加到目标数字的距离,两头找取最小值 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e3 + 10; 11 const int INF = 0x3f3f3f3f; 12 char s[MAXN],

CF #374 (Div. 2) D. 贪心,优先队列或set

1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优先队列 #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(