codeforces659c Tanya and Toys map

Source: Internet
Author: User

Tanya and Toys
In Berland recently a new collection of the 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 have managed to collect n different types of toys A1, A2, ..., a 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 would 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 have.

Tanya wants to has as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya are too little, so she-asks you-to-help.

Input
The first line contains-integers n (1≤n≤100) and M (1≤m≤109)-the number of types of toys that Tanya Alre Ady has and the number of bourles, her mom was 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 have.

Output
In the first line print a single integer k-the number of different types of toys that Tanya should choose so that the Nu Mber of different types of toys in She collection is maximum possible. Of course, the total cost of the selected toys should is 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 is multiple answers, you could print any of the them. Values of TI can is 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 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 has already been bought), it is Impossibl E to buy both and more toys.

The main idea: buy a toy numbered I, now has n (1≤n≤100 000) a toy, their number is a1,a2...an (1≤AI≤1E9), now rich M, already have toys will not buy, output the most buy the number of toys, and their number, the output of the number order arbitrary , if there is more than one set of solutions for any output.

Idea: Must be as far as possible to take the number of small, while already have some can not take

Note: The open array simulation will certainly WA, the data to 1e9, with the map

#include <bits/stdc++.h>using namespaceStd;map<int,int>Mpint;inta[200000];intMain () {intN, M, I, T, k;scanf ("%d%d", &n, &m); for(i=1; i<=n;i++) {scanf ("%d", &t); Mpint[t]=1;}Long Longsum=m; for(k=1, i=1; i<1e9;i++){    if(!Mpint[i]) {Sum-=i; A[k++]=i; }    if(sum<0)         Break;} printf ("%d\n", K-2); for(i=1; i<=k-2; i++) printf ("%d", A[i]);return 0;}

codeforces659c Tanya and Toys map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.