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 ...
随机推荐
- Linux学习系列之memcached
memcached简介 一.memcached是什么 memcached是一个开源的.支持高性能.高并发的分布式内存缓存系统 mem+cache+daemon:分布式内存缓存守护进程 memcache ...
- 推荐IOS开发3个工具:Homebrew、TestFight、Crashlytics-b
1. Homebrew 什么是Homebrew? Homebrew is the easiest and most flexible way to install the UNIX tools App ...
- (六)Net Core项目使用Controller之一 c# log4net 不输出日志 .NET Standard库引用导致的FileNotFoundException探究 获取json串里的某个属性值 common.js 如何调用common.js js 筛选数据 Join 具体用法
(六)Net Core项目使用Controller之一 一.简介 1.当前最流行的开发模式是前后端分离,Controller作为后端的核心输出,是开发人员使用最多的技术点. 2.个人所在的团队已经选择 ...
- WPF自学入门(十一)WPF MVVM模式Command命令 WPF自学入门(十)WPF MVVM简单介绍
WPF自学入门(十一)WPF MVVM模式Command命令 在WPF自学入门(十)WPF MVVM简单介绍中的示例似乎运行起来没有什么问题,也可以进行更新.但是这并不是我们使用MVVM的正确方式 ...
- git基础之创建ssh公钥和密钥
用git管理过程中,不想每次输入username和password.解决的方法例如以下; 1 . 链接换成ssh协议. 2 . 生成公钥. 3. 加入ssh公钥到gitserver. 打开gitbas ...
- 关于mysql建立索引 复合索引 索引类型
这两天有个非常强烈的感觉就是自己在一些特别的情况下还是hold不住,脑子easy放空或者说一下子不知道怎么去分析问题了,比方,问"hash和btree索引的差别",这非常难吗.仅仅 ...
- python 爬虫必知必会
#python爬虫 #新闻数据 #机器学习:股票数据获取及分析 #网络搜索引擎的一个部件 #Http协议 #正则表达式 #多线程,分布式 #http报文展示 #Http 应答报文介绍 #1.应答码 # ...
- CentOS 6.4安装Ganglia
samba 1.这里安装的是3.1.7版本,web前端是最新版本,安装前期环境(yum源用的是本地的) yum -y insatll php php-gd rrdtools apr-devel apr ...
- Eclipse Android环境配置
1.离线安装ADT插件,先将ZIP包下载 Help- Install New Software- Add 重启 2.WIndows -Preference设置SDK目录
- convex hull
1 什么是convex hull 就是凸包,是计算几何中的一个概念,计算几何是计算机图形学的基础之一. 对于二维平面来说是这样的:对于二维平面上的点集,凸包是位于最外层的点构成的包围其它所有的点的凸多 ...