Codeforces 659C Tanya and Toys

逃离我推掉我的手 2022-07-18 01:48 106阅读 0赞

Codeforces 659C Tanya and Toys

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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, …, a**n 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, …, a**n (1 ≤ a**i ≤ 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, …, t**k (1 ≤ t**i ≤ 109) — the types of toys that Tanya should choose.

If there are multiple answers, you may print any of them. Values of t**i can be printed in any order.

Examples

input

  1. 3 7
  2. 1 3 4

output

  1. 2
  2. 2 5

input

  1. 4 14
  2. 4 6 12 8

output

  1. 4
  2. 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.

题目链接:点击打开链接

简单贪心

代码:

  1. #include<stdio.h>
  2. #include<algorithm>
  3. #include<map>
  4. #include<set>
  5. using namespace std;
  6. long long n,m;
  7. int main()
  8. {
  9. while(~scanf("%lld%lld",&n,&m))
  10. {
  11. map<long long,int> toy;
  12. int ans=0;
  13. set<long long> ansi;
  14. for(int i=0;i<n;i++)
  15. {
  16. long long temp=0;
  17. scanf("%lld",&temp);
  18. toy[temp]++;
  19. }
  20. for(int i=1;i<=1000000000&&m>=0;i++)
  21. {
  22. if(toy[i]==0)
  23. {
  24. m-=i;
  25. if(m>=0)
  26. {
  27. ans++;
  28. ansi.insert(i);
  29. }
  30. }
  31. }
  32. printf("%d\n",ans);
  33. set<long long>::iterator p;
  34. for(p=ansi.begin();p!=ansi.end();p++)
  35. {
  36. printf("%lld ",*p);
  37. }
  38. printf("\n");
  39. }
  40. return 0;
  41. }

发表评论

表情:
评论列表 (有 0 条评论,106人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CodeForces 510C Fox And Names

    一道拓扑排序题!! 注意判断各种情况,两个字符串比较的时候,从左向右开始比较,当出现不同的字母后,不再向后比较。一个是另一个的前缀,那么长的在后面。 当给出的顺序出现环的时