C - Tanya and Toys

来源:互联网 发布:爬虫数据采集兼职 编辑:程序博客网 时间:2024/06/07 22:08
C - Tanya and Toys
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 659C

Description

In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1to 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.

Sample Input

Input
3 71 3 4
Output
22 5 
Input
4 144 6 12 8
Output
47 2 3 1

FAQ | About Virtual Judge | Forum | Discuss | Open Source Project
All Copyright Reserved ©2010-2014 HUST ACM/ICPC TEAM 

1136242673 's source code for C
Memory: 3904 KB Time: 78 MSLanguage: GNU G++ 4.9.2 Result: AcceptedPublic:  

Select All
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<queue>#include<cctype>#define max(a,b)(a>b?a:b)#define min(a,b)(a<b?a:b)#define INF 0x3f3f3f3fusing namespace std;#define N 110000long long a[N],b[N];int Find(long long a[],long long x,int l,int r){    int mid=(l+r)/2;    if(a[l]>x || a[r]<x || l > r)        return 0;    else    {       if(x==a[mid])           return 1;       if(a[mid]<x)        return Find(a,x,mid+1,r);      else        return Find(a,x,l,mid-1);    }}int main(){    int i,  n, cnt;    long long  m, sum;    while(scanf("%d%I64d",&n,&m)!=EOF)    {        for(i=1; i<=n; i++)        {            scanf("%I64d",&a[i]);        }        sort(a+1,a+n+1);        sum=cnt=0;        for(i=1; i<=m; i++)        {            if(Find(a,i,1,n)!=1)            {                if(sum+i<=m)                {                    b[cnt]=i;                    cnt++;                    sum+=i;                }                else                {                    break;                }            }        }        printf("%d\n",cnt);        for(i=0; i<cnt; i++)        {            printf("%I64d%c",b[i],i==cnt-1?'\n':' ');        }    }    return 0;}

用 二分搜索 避免超时! WA了好几次 

0 0
原创粉丝点击