C. Tanya and Toys
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
3 7
1 3 4
output
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_模拟的更多相关文章

  1. CF 1005A Tanya and Stairways 【STL】

    Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...

  2. CodeForces - 1005A-Tanya and Stairways(模拟)

    Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairw ...

  3. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  4. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  5. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  6. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  7. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

  8. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

  9. javascript动画系列第一篇——模拟拖拽

    × 目录 [1]原理介绍 [2]代码实现 [3]代码优化[4]拖拽冲突[5]IE兼容 前面的话 从本文开始,介绍javascript动画系列.javascript本身是具有原生拖放功能的,但是由于兼容 ...

随机推荐

  1. Linux多线程及线程同步简单实例

    一.多线程基本概念 1. 线程的基本概念 ① 线程就是轻量级的进程 ②线程和创建他的进程共享代码段.数据段 ③线程拥有自己的栈 2. 在实际应用中,多个线程往往会访问同一数据或资源,为避免线程之间相互 ...

  2. python练习六十八:字符串练习

    题目:一个商城在搞抽奖的活动,需要在搞活动的宣传单上印刷优惠卷的验证码,验证码规定20位,生成100个 先来个简单的,20位码中只取数字 import random def num_1(num): l ...

  3. python进制转换或数据格式转换

    以下是部分进制转换的,都是python内置函数 int(x [,base ])         将x转换为一个整数    long(x [,base ])        将x转换为一个长整数    f ...

  4. Angular JS ng-model对<select>标签无效的情况

    使用场景一: <select ng-if="item.award_type==1" id="award{{$index+1}}" name="X ...

  5. Silverlight 鼠标双击 事件

    Silverlight 双击事件例子 <UserControl x:Class="MouseDbClick.MainPage" xmlns="http://sche ...

  6. CAD安装失败怎样卸载CAD 2019?错误提示某些产品无法安装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  7. PHP速学

    基本代码 <?php echo "Hello world";?> 变量定义 <?php $a=true; $bool_value=true; $integer_v ...

  8. stm32 输入捕获学习(二)

    (本文参考STM32  开发指南 V1.3   -- ALIENTEK 战舰 STM32 开发板库函数教程 ) 1. 实验设计 我们用 TIM5 的通道 1(PA0)来做输入捕获,捕获 PA0 上高电 ...

  9. MVC中的验证码

    下面是一个完整的mvc controller类 public class CodeController : Controller { private const string CODE = " ...

  10. 1.C#中的注释符

    1.软件行业的道德规范 (1).程序员在日常写代码的过程中,一定要养成注释的好习惯,方便后面对理解和使用. (2).在给标识符命名的时候一定要规范,有理有据的,名字不能瞎写. 2.注释 注释符的作用: ...