C. Tanya and Toys_模拟
1 second
256 megabytes
standard input
standard output
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to109. A toy from the new collection of the i-th type costs i bourles.
Tania has managed to collect n different types of toys a1, a2, ..., an from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than m bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
The first line contains two integers n (1 ≤ n ≤ 100 000) and m (1 ≤ m ≤ 109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the types of toys that Tanya already has.
In the first line print a single integer k — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed m.
In the second line print k distinct space-separated integers t1, t2, ..., tk (1 ≤ ti ≤ 109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of ti can be printed in any order.
3 7
1 3 4
2
2 5
解题报告:
1、数据达到10^9,开数组模拟是肯定不可以的。
#include <bits/stdc++.h> using namespace std; const int N=;
const int INF=; map<int,bool> have;
vector<int> ans; int main()
{
int n,m,x; cin>>n>>m; for(int i=;i<=n;i++)
{
scanf("%d",&x);
have[x]=true;
} for(int i=;m>=i;i++)
{
if(have[i]) continue;
ans.push_back(i);
have[i]=true;
m-=i;
} cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++)
printf("%d ",ans[i]);
return ;
}
C. Tanya and Toys_模拟的更多相关文章
- CF 1005A Tanya and Stairways 【STL】
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...
- CodeForces - 1005A-Tanya and Stairways(模拟)
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- 故障重现, JAVA进程内存不够时突然挂掉模拟
背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...
- Python 爬虫模拟登陆知乎
在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...
- HTML 事件(四) 模拟事件操作
本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4. ...
- 模拟AngularJS之依赖注入
一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...
- webapp应用--模拟电子书翻页效果
前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...
- javascript动画系列第一篇——模拟拖拽
× 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...
随机推荐
- thinkPHP5.0验证码不显示
1.使用composer安装时,验证码无法正常显示 主要是因为验证码扩展库的版本安装不正常,官方的5.0版本的扩展库版本号都是1.*,默认安装的是2.0版本,2.0版本均为ThinkPHP5.1版本专 ...
- 第八章:BOM
/* * bom: * 提供了浏览器接口; * w3c为了把javascript最基本的只是标准化已经将bom的主要方面纳入html5规范*/ console.log(window); !(funct ...
- docker 设置固定ip、配置网络
Docker安装后,默认会创建下面三种网络类型 $ docker network ls NETWORK ID NAME DRIVER SCOPE 9781b1f585ae bridge bridge ...
- Dev Express Report 学习总结(八)Dev Express Reports 常见问题总结
1. 在新建ASP.NET Dev Express Report时的两种方式: A. 右键Add DevExpress Item->New Item->All->从Web Repor ...
- Dev Express Report 学习总结(六)Dev Express Reports自定义Summary
在我们使用DevExpress开发报表的过程中,对于页面中复杂的数据合计,我们可能会使用到自定义Summary.下面通过一个例子来进行说明: 首先,我建立了如上图所示的报表页面,其中的数据源来自cla ...
- Android NDK开发 Jni中Debug(三)
下载LLDB 配置Android Native - Debugger 调式结果如下 #include <jni.h> #include <string.h> #include& ...
- density peak聚类算法
一个ppt很好讲解了density peak算法的要义:https://pan.baidu.com/s/1oCR-gF1o1kfV-L7HnIa8og 算法来源自论文:Clustering by fa ...
- Redis Intro - Dict
https://segmentfault.com/a/1190000004850844
- 解决 eclipse cdt 运行时控制台乱码解决
1 点击黑色 倒三角 按钮 选择 run configurations 2 2.1 点击new 添加 LANG = en_US 2.2 选择 replace native environment wi ...
- dos文件格式转换为Unix文件格式
做linux开发的,一般还是在windows上装个虚拟机,在windows上开发, 所以就会出现dos文件与unix文件格式不一致,当windows上的文件在linux上用的时候,经常在每行的末尾会出 ...