codeforces659C
Tanya and Toys
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
3 7
1 3 4
2
2 5
4 14
4 6 12 8
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的更多相关文章
随机推荐
- PHP创建socket服务
PHP可以创建socket服务. 先熟悉几个php网络方面的函数,操作手册地址 http://php.net/manual/zh/ref.sockets.php 简单介绍下socket,它表示套接字 ...
- 十二省联考 - JLOI2019 游记
十二省联考 - JLOI 2019 游记 想了想,还是起一个副标题吧 一场失败的胜利 Day -inf 想了想,还是从头开始说吧. 其实考完NOIP之后,大概估算一下,吉林省队的数量还算是比较乐观的, ...
- Ambari 使用 Hive View 异常处理
异常:进入Hive View提示user home check fail 详细日志:Service 'userhome' check failed: java.io.FileNotFoundExcep ...
- C#发邮件_EmailHelper
EmailHelper类 public class EmailHelper { /// <summary> /// 发送邮件 /// </summary> /// <pa ...
- 分布式系统消息中间件——RabbitMQ的使用基础篇
分布式系统消息中间件——RabbitMQ的使用基础篇
- 安卓权限申请处理框架Android-UsesPermission
安卓权限申请封装处理框架.测试支持4.0+.项目源于正式处理Android权限问题时,没找到简单.能满足被拒绝权限自动会到系统设置处理的框架,按自己的编程习惯造一个熟悉的轮子还是蛮好的.第一次使用An ...
- Linux Namespace : Network
Network namespace 在逻辑上是网络堆栈的一个副本,它有自己的路由.防火墙规则和网络设备.默认情况下,子进程继承其父进程的 network namespace.也就是说,如果不显式创建新 ...
- Python股票分析系列——获得标普500的所有公司股票数据.p6
该系列视频已经搬运至bilibili: 点击查看 欢迎来到Python for Finance教程系列的第6部分. 在之前的Python教程中,我们介绍了如何获取我们感兴趣的公司名单(在我们的案例中是 ...
- 使用Thrift让Python和C#可以相互调用
在聊如何使用Thrift让Python和C#可以互相调用之前,我们先来看看下面的话题. 一.什么是微服务.微服务的特征.诞生的背景.优势和不足 微服务:使用一套小服务来开发单个应用的方式,每个服务运行 ...
- 三次握手复习TCP
临近下班,突然想起三次握手的概念有点模糊. 大学时候的<计算机网络>是英语版的,那时候学习迷迷糊糊的.大概记得一个模型罢了. 幸好,大学基本所有的书都卖了,就是计算机网络没卖.待会回去看看 ...