cf - #346 C-Tanya and Toys

#include <iostream>
#include <algorithm>
using namespace std;
/*******************************************************************************************************************
                                 贪心:排序,水过去
*******************************************************************************************************************/
#define MAXN 100010

int a[MAXN],s[MAXN];

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0; i<n; i++)
            cin>>a[i];
        sort(a, a+n);
        int ans,t,k;
        ans = 0;
        t = k = 0;
        for(int i=1; ; i++){
            if(i == a[k]){k++; continue;}
            if(m >= i){
                m -= i;
                s[t++] = i;
                ans++;
            }
            else break;
        }
        cout<<ans<<endl;
        for(int i=0; i<t; i++){
            if(i == 0)
                cout<<s[i];
            else
                cout<<" "<<s[i];
        }
        cout<<endl;
    }
    return 0;
}


posted on 2016-04-12 23:46  Jstyle  阅读(121)  评论(0编辑  收藏  举报

导航