Tanya and Toys

CodeForces - 659C

In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. 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
Input
4 14
4 6 12 8
Output
4
7 2 3 1

Note

In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys.

sol:XJB贪心,复杂度是有保证的,1e9到1e5的等差序列就炸了,所以O(枚举)一定是可行的

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,ans[N];
map<int,bool>Map;
int main()
{
int i;
R(n); R(m);
for(i=;i<=n;i++) Map[read()]=;
for(i=;;i++) if(!Map[i])
{
if(m>=i)
{
ans[++*ans]=i; m-=i;
}
else break;
}
Wl((*ans));
for(i=;i<=*ans;i++) W(ans[i]);
return ;
}
/*
Input
3 7
1 3 4
Output
2
2 5 Input
4 14
4 6 12 8
Output
4
7 2 3 1
*/

codeforces659C的更多相关文章

随机推荐

  1. 一道很有意思的java线程题

    这几天看结城浩的<java多线程设计模式>,跟着做一些习题,有几道题目很有意思,记录下自己的体会. 首先是题目(在原书212页,书尾有解答): public class Main { pu ...

  2. Linux进程管理 (2)CFS调度器

    关键词: 目录: Linux进程管理 (1)进程的诞生 Linux进程管理 (2)CFS调度器 Linux进程管理 (3)SMP负载均衡 Linux进程管理 (4)HMP调度器 Linux进程管理 ( ...

  3. 百度地图JSAPI浏览器定位

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的秘钥 ...

  4. IOException: Sharing violation on path *****

    Unity代码中删除文件或者文件夹时,可能会报这个错.翻译成白话文就是:你在其它地方打开了这个文件/文件夹   把打开的地方关了就是了.

  5. 【PHP快速入门】 第二节 php基本语法

    1.什么地方能写PHP代码? php代码需要写在php标识符内,就是这个东西: 在我们编写一个php程序时,必须要在这个文件里面写上 2.PHP语句要不要加分号? 有的地方要加,有的地方不要加.(似乎 ...

  6. 抛弃配置后的Spring终极教程

    一:前言 Spring 有XML配置和注解两种版本,我个人非常喜欢使用注解,相当热衷Spring boot! 对于Spring,核心就是IOC容器,这个容器说白了就是把你放在里面的对象(Bean)进行 ...

  7. iOS开发简记(5):设备唯一标识与全局变量

    这里记录两个iOS开发中经常用到的知识点,一个是唯一标识,一个是全局变量. (1)唯一标识 唯一标识一台设备(比如iPhone.iPad等)是一个基本的实现与业务上的需求,因为这个唯一标识在许多场景都 ...

  8. hibernate中实体与数据库中属性对应的类型

    常用的字段及类型,在数据库中字段名称若与实体对应的属性字段名称相同,hibernate可以自动映射,在一些情况下hibernate可能报错这时候有的错误可以通过指定对应的类型避免.下面给出一些常用的 ...

  9. Python—反射

    反射 1 什么是反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它 ...

  10. Day5 Pyhton基础之编码与解码(四)

    1.编码与解码 1.1现在常用的编码类型