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. Springboot知识点

    1. Spring boot简介 主要用来简化spring开发,快速地创建独立的spring项目,并且与云计算天然集成. 2. @Controller  标记一个类是Controller . 3. @ ...

  2. 算法相关——Java排序算法之希尔排序(五)

    个子块,即{3,5},{1,0},{5,2},{9,4},{6,12},将每个子块进行插入排序(即第i位与第i+5位进行比较交换),初步排序结果为{3,0,2,4,6,5,1,5,9,12}.希尔排序 ...

  3. 【深度学习】一文读懂机器学习常用损失函数(Loss Function)

    最近太忙已经好久没有写博客了,今天整理分享一篇关于损失函数的文章吧,以前对损失函数的理解不够深入,没有真正理解每个损失函数的特点以及应用范围,如果文中有任何错误,请各位朋友指教,谢谢~ 损失函数(lo ...

  4. 五子棋(无AI winform gdi+)

    之前无意间在博客园看到一篇用深度学习玩马里奥的文章,于是就想做这个小东西来测试人工智能算法(准备用PYTHON的库,对神经网络的梦已经做了好多年了,但是太难了,一直懒得动它),本来是想用WPF做UI, ...

  5. Pandas基础使用

    Pandas是基于NumPy的一种工具,该工具是为了解决数据分析任务而创建的. 1.导入pandas import pandas as pd 2.pandas数据类型: 1)Series:一维数据类型 ...

  6. LCT维护删除时间最晚生成树

    用来做动态图问题. 维护一棵删除时间最晚的生成树,这样好处是加入一条非树边时可以直接判断加还是不加,没有现在不加入而之后再加入的情况.要是我比你先被删,那我就完全没必要加.否则你现在就可以被删除掉.

  7. 第十二届湖南省赛G - Parenthesis (树状数组维护)

    Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...

  8. 通过设置线程池的最小线程数来提高task的效率,SetMinThreads。

    http://www.cnblogs.com/Charltsing/p/taskpoolthread.html task默认对线程的调度是逐步增加的,连续多次运行并发线程,会提高占用的线程数,而等若干 ...

  9. mysql 小数转换成百分数查出(保留两位小数百分数)

    SELECT id as 'ID',GROUP_CONCAT(concat(truncate(royalties *100,2),'%')) as '比例' FROM yser FROM id in( ...

  10. Is-a

    在知识表示.面向对象程序设计与面向对象设计的领域里, is-a(英语:subsumption,包含架构)指的是类的父子继承关系, 例如类D是另一个类B的子类(类B是类D的父类). 换句话说,通常&qu ...