codeforces 540 B School Marks【贪心】

题意:一共n个数,给出其中k个数,要求这n个数的中位数为y,这n个数的和不超过x,补全剩下的n-k个数

先统计给出的k个数里面比中位数小的数,

如果cnt<=n/2,说明中位数还没有出现,把这n/2-cnt个数都补上1,剩下的都补上y

如果cnt>n/2,说明中位数不存在

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
14
15 typedef long long LL;
16 const int INF = (1<<30)-1;
17 const int mod=1000000007;
18 const int maxn=100005;
19
20 int a[maxn];
21
22 int main(){
23     int n,k,p,x,y;
24     cin>>n>>k>>p>>x>>y;
25     int ans=0;
26     int sum=0;
27     for(int i=1;i<=k;i++){
28         cin>>a[i];
29         sum+=a[i];
30         if(a[i]<y) ans++;
31     }
32     int l,r;
33
34     if(ans<=n/2){
35         l=min(n/2-ans,n-k);
36         r=n-l-k;
37         sum+=l+r*y;
38
39         if(sum>x) printf("-1\n");
40         else{
41             for(int i=1;i<=l;i++) printf("1 ");
42             for(int i=1;i<=r;i++) printf("%d ",y);
43             printf("\n");
44         }
45     }
46     else printf("-1\n");
47     return 0;
48 }

g0---oooooooooo

时间: 2024-10-21 15:41:20

codeforces 540 B School Marks【贪心】的相关文章

Codeforces 442B Andrey and Problem(贪心)

题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,现在他有n个朋友,每个朋友想出题目的概率为pi,但是他可以同时向多个人寻求帮助,不过他只能要一道题,也就是如果他向两个人寻求帮助,如果两个人都成功出题,也是不可以的. 解题思路:贪心,从概率最大的人开始考虑,如果询问他使得概率变大,则要询问. #include <cstdio> #include <cstring> #include <a

Codeforces Round #300-Tourist&#39;s Notes(贪心)

Tourist's Notes Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level

Codeforces 432E Square Tiling(构造+贪心)

我们通常这么写 using (SqlDataReader drm = sqlComm.ExecuteReader()) { drm.Read();//以下把数据库中读出的Image流在图片框中显示出来. MemoryStream ms = new MemoryStream((byte[])drm["Logo"]); Image img = Image.FromStream(ms); this.pictureBox1.Image = img; } 我的写数据 private void b

(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

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 798D Mike and distribution - 贪心

Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, 

codeforces 349B Color the Fence 贪心,思维

1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1-9每个字母分别要ai升油漆,问最多可画多大的数字. 贪心,也有点考思维. #include<bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3f int main() { int v,a[1

codeforces 343C Read Time 二分 + 贪心

http://codeforces.com/problemset/problem/343/C 题意: 有一些磁头,给出了起始的位置,给出了一些磁盘中需要访问的地点.求这些磁头移动的最小的次数. 思路: 二分找出满足要求的最小的时间,对于当前尝试的时间进行贪心判断是否可用.对于贪心,因为每一个磁头都需要读到还没有人读过的最左边的地方.如果这个都不能满足,那么这个时间是不可以的. 在这基础上,对于同样的这么多时间,尽可能的让这个磁头读到能读到的最右边,这样就可以将还没有读过的地方尽可能的往右推. 如

Codeforces 540 E. Infinite Inversions

http://codeforces.com/contest/540/problem/E 离散化 + 树状数组. 先处理出所有会变动的位置,然后求出这些位置上最终的数值. 接着分两步,先求出这些元素之间的逆序数,再求每个元素和其余不变动元素间的逆序数 版权声明:本文为博主原创文章,未经博主允许不得转载.