Codeforces-C. 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 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

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.

Means:

问你用m元买没买过的玩具最多能买多少

Solve:

水题,MLE?硬是被我用map怼过去

Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 static const int MAXN = 1e9;
 4 map <int , bool> vis;
 5 int n , m;
 6 vector <int> ans;
 7 int main(int argc, char const *argv[])
 8 {
 9     int x;
10     scanf("%d%d" , &n , &m);
11     for(int i = 0 ; i < n ; ++i)
12     {
13         scanf("%d" , &x);
14         vis[x] = 1;
15     }
16     int num = 0;
17     for(int i = 1 ; i <= MAXN && m > 0 ; ++i)
18     {
19         if(i > m)
20             break;
21         if(vis[i] == 1)
22             continue;
23         else
24         {
25             ans.push_back(i);
26             ++num;
27             m -= i;
28         }
29     }
30     printf("%d\n" , num);
31     for(int i = 0 ; i < num ; ++i)
32         printf("%d " , ans[i]);
33     return 0;
34 }

时间: 2024-10-14 23:01:00

Codeforces-C. Tanya and Toys(水题)的相关文章

[2016-03-31][codeforces][659C][Tanya and Toys]

时间:2016-03-31 23:49:13 星期四 题目编号:[2016-03-31][codeforces][659C][Tanya and Toys].md 题目大意:有$10^9$种物品,第i种物品价值i,已经用用n个物品,给m元,问最多能买多少个还没拥有的物品 分析:贪心,从最低的开始买起,假设$m = 10^9$,那么也买的物品也不超过$10^6$个,因为$\frac{(1+k)k}{k} < 10^9$ 遇到的问题:答案可能为0 #include <algorithm> #

CodeForces 707A Brain&#39;s Photos (水题)

题意:给一张照片的像素,让你来确定是黑白的还是彩色的. 析:很简单么,如果有一种颜色不是黑白灰,那么就一定是彩色的. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #i

codeforces 710A A. King Moves(水题)

题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <bits/stdc++.h> #include <stack> #include &l

codeforces 696A Lorenzo Von Matterhorn 水题

这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽量不用 #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #

CodeForces 589I Lottery (暴力,水题)

题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cma

CodeForces 518A Vitaly and Strings (水题,字符串)

题意:给定两个相同长度的字符串,让你找出一个字符串,字典序在两都之间. 析:这个题当时WA了好多次,后来才发现是这么水,我们只要把 s 串加上,然后和算数一样,该进位进位,然后再和 t 比较就行. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <cstring> #in

Codeforces gym 100685 C. Cinderella 水题

C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C Description Cinderella is given a task by her Stepmother before she is allowed to go to the Ball. There are N (1 ≤ N ≤ 1000) bottles with water in th

codeforces 659C Tanya and Toys

题目链接:http://codeforces.com/problemset/problem/659/C 题意: n是已经有的数字,m是可用的最大数字和 要求选自己没有的数字,且这些数字的数字和不能超过m 且要求可选的数字的数目越多越好 输出一种答案即可 解题思路: 刚开始想开一个bool型的1e9的数组,然后判断即可 可是交上去发现内存超限 后来把1e9的数组改成2*1e6的数组即可 具体原因应该从数学数字和方面考虑 具体代码如下: #include<bits/stdc++.h> using

CodeForces 709C Letters Cyclic Shift (水题)

题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果到最后一位了还没开始减, 就减最后一位. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <c