codeforces 659C C. Tanya and Toys(水题+map)
题目链接:
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
4 14
4 6 12 8
4
7 2 3 1
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.
题意:
问选没有过的toy能最多选多少个;
思路:
从小到大贪心,用map记录是否已经有过;
AC代码:
/*
2014300227 659C - 50 GNU C++11 Accepted 93 ms 7380 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int n,m,x;
int a[N],ans[N];
map<int,int>mp;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%d",&x);
mp[x]=;
}
long long sum=;
int cnt=;
for(int i=;i<=1e9;i++)
{
if(!mp[i])
{
if(sum+(long long)i<=m)
ans[cnt++]=i,sum+=(long long)i;
else
{
break;
}
}
}
printf("%d\n",cnt);
for(int i=;i<cnt;i++)
{
printf("%d ",ans[i]);
} return ;
}
codeforces 659C C. Tanya and Toys(水题+map)的更多相关文章
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
随机推荐
- vs调试,监控变量
- 多系统启动光盘制作---WIN7+WinXP+老毛桃PE工具箱
1.工具: ⑴ Windows 7 ISO: ⑵ Windows XP ISO: ⑶ 老毛桃U盘启动盘制作工具V2013 制作得的ISO (含PE.DOS等): ⑷ UltraISO.EasyBoot ...
- prop()方法和attr()方法以及区别
prop()方法: prop() 方法设置或返回被选元素的属性和值. 当该方法用于返回属性值时,则返回第一个匹配元素的值. 当该方法用于设置属性值时,则为匹配元素集合设置一个或多个属性/值对. 注意: ...
- FreeRTOS在神舟IV号开发板的应用demo
下面一个可以直接编译运行的例子,FreeRTOS的版本是V7.1.0,芯片是STM32F107VCT6,使用的开发环境是Keil uVision5. 这里例子创建了四个任务,每个任务控制一个LED的亮 ...
- 大数据:Hive常用参数调优
1.limit限制调整 一般情况下,Limit语句还是需要执行整个查询语句,然后再返回部分结果. 有一个配置属性可以开启,避免这种情况---对数据源进行抽样 hive.limit.optimize.e ...
- 【Android】图片(文件)上传的请求分析结构
怎么在android中上传文件,即怎么用Java向服务器上传文件.上传图片,这是个老问题了,在网上能搜到现成的代码,很多朋友用起来也比较熟了,但是为什么这么写,可能很多朋友并不清楚,这篇文章就来分析一 ...
- 基于EasyNVR二次开发实现业务需求:直接集成EasyNVR播放页面到自身项目
EasyNVR着重点是立足于视频能力层,但是自身也是可以作为一个产品使用的.这就更加方便了应用层的使用. 由于业务需求的缘故,无法使用实体项目展示. 案例描述 该业务系统是国内某大型显示屏生产企业内部 ...
- JAVA解析XML之SAX方式
JAVA解析XML之SAX方式 SAX解析xml步骤 通过SAXParseFactory的静态newInstance()方法获取SAXParserFactory实例factory 通过SAXParse ...
- C#使用tesseract3.02识别验证码模拟登录(转)
转自http://www.cnblogs.com/JinJi-Jary/p/5625414.html
- cmake是什么
1 cmake是什么 cmake是一个管理软件build过程的工具.它并不会直接build处软件可执行文件本身,而是build出可以build出软件本身的全部工程文件,比如makefiles.xcod ...