CF540B School Marks
思路:
贪心。
实现:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std; int n, p, k, x, y;
vector<int> a;
int main()
{
cin >> n >> k >> p >> x >> y;
int sum = , tmp = ;
for (int i = ; i < k; i++)
{
cin >> tmp;
a.push_back(tmp);
sum += a[i];
}
if (x - sum < n - k)
{
puts("-1");
}
else
{
bool flag = true;
vector<int> res;
sort(a.begin(), a.begin() + k);
int now = k;
sum = x - sum;
while (now < n)
{
int pos = lower_bound(a.begin(), a.begin() + now, y) - a.begin();
if (pos < now / )
{
a.insert(a.begin(), );
res.push_back();
sum--;
}
else
{
a.insert(a.begin() + pos, y);
res.push_back(y);
sum -= y;
}
if (sum < )
{
puts("-1");
flag = false;
break;
}
now++;
}
if (flag)
{
if (a[n >> ] >= y)
{
for (int i = ; i < n - k; i++)
{
cout << res[i] << " ";
}
puts("");
}
else
{
puts("-1");
}
}
}
return ;
}
CF540B 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 ...
随机推荐
- Ubuntu 16.04安装unrar解压RAR文件
除了7zip:http://www.cnblogs.com/EasonJim/p/7124306.html之外,还可以安装unrar进行解压RAR文件. 安装 sudo apt-get install ...
- [Algorithms] Determine if a string is a palindrome
A palindrome is a string that reads the same forward and backward, for example, radar, toot, and mad ...
- andorid自己定义ViewPager之——子ViewPager滑到边缘后直接滑动父ViewPager
近期的项目中,有一个需求要用ViewPager中嵌套ViewPager去实现整个效果.没做不论什么处理做出来后,仅仅能不停的滑动子ViewPager,父ViewPager就无法滑动了,这样肯定是不满足 ...
- antd 的 Table 遇到的 bug
1.报错情况 /* autoprefixer: off */ filter: progid\:DXImageTransform\.Microsoft\.Blur(PixelRadius\=1, Mak ...
- rsh 无秘钥登陆配置
/etc/hosts.equiv里的主机不须要提供password就能够訪问本机./etc/host.equiv 要和~/.rhosts文件连用. [root@web-htl2-01 ~]# cat ...
- HDU1215--七夕节
找出小于N的全部因子的和,N比較大,非常明显要打表来做,不然肯定会超时 方法就是枚举范围内每一个整数.然后再枚举范围内这个整数的全部的倍数,加上这个数 由于这个整数的倍数中一定含有这个整数因子,这样速 ...
- ABAP学习之旅——多种方式建立模块化功能
在ABAP中.有多种方法能够建立模块化的功能. 以下依次对其种三种进行介绍. 一. 使用子程序(Subroutine) 1. 基本的语法: FORM subname. ...
- WPF自学入门(十一)WPF MVVM模式Command命令 WPF自学入门(十)WPF MVVM简单介绍
WPF自学入门(十一)WPF MVVM模式Command命令 在WPF自学入门(十)WPF MVVM简单介绍中的示例似乎运行起来没有什么问题,也可以进行更新.但是这并不是我们使用MVVM的正确方式 ...
- Python爬虫开发【第1篇】【正则表达式】
非结构化数据:HTML(正则表达式.XPath.CSS选择器) 结构化数据:JSON文件(JSON Path.转化为Python类型进行操作) XML文件(转化成Python类型.XPath.CSS选 ...
- c# Action,Func,Predicate委托
System命名空间下已经预先定义好了三中泛型委托,Action,Func和Predicate,这样我们在编程的时候,就不必要自己去定义这些委托了 Action是没有返回值的 Func是带返回值的 不 ...