Codeforces Round #346 (Div. 2) C Tanya and Toys
C. Tanya and Toys
题目链接http://codeforces.com/contest/659/problem/C
Description
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 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
3 7
1 3 4
Sample Output
2
2 5
题意:
给你n个数字,求1~1e9之间除了那n个数字最多可以选多少个不同的数字,使和小于等于m。
题解:
从1开始枚举,只要可以满足条件则从小到大枚举每个可能,贪心即可必然小的必须选。这里使用的bitset速度很快。
代码:
#include<bits/stdc++.h>
using namespace std;
bitset <1000000100> s;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int t;
for (int i = 1;i <= n;i++){scanf("%d",&t);s[t]=1;}
int c = 0;
int mm = m;
for (int i = 1;i <= 1000000000;i++){
if (s[i])
continue;
if (mm < i)
break;
mm-=i;
c++;
}
mm = m;
printf("%d ",c);
for (int i = 1;i <= 1000000000;i++){
if (s[i])
continue;
if (mm < i)
break;
mm-=i;
printf("%d ",i);
}
}
Codeforces Round #346 (Div. 2) C Tanya and Toys的更多相关文章
- Codeforces Round #346 (Div. 2) C. Tanya and Toys 贪心
C. Tanya and Toys 题目连接: http://www.codeforces.com/contest/659/problem/C Description In Berland recen ...
- Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...
- Codeforces Round #346 (Div. 2) C题
C. Tanya and Toys In Berland recently a new collection of toys went on sale. This collection consist ...
- Codeforces Round #288 (Div. 2)D. Tanya and Password 欧拉通路
D. Tanya and Password Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/508 ...
- Codeforces Round #346 (Div. 2) A Round-House
A. Round House 题目链接http://codeforces.com/contest/659/problem/A Description Vasya lives in a round bu ...
- Codeforces Round #346 (Div. 2) A. Round House 水题
A. Round House 题目连接: http://www.codeforces.com/contest/659/problem/A Description Vasya lives in a ro ...
- Codeforces Round #346 (Div. 2) D Bicycle Race
D. Bicycle Race 题目链接http://codeforces.com/contest/659/problem/D Description Maria participates in a ...
- Codeforces Round #346 (Div. 2) B Qualifying Contest
B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...
- Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)
Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai. She plans to eat e ...
随机推荐
- Centos 64位 Install certificate on apache 即走https协议
Centos 64位 Install certificate on apache 即走https协议 一: 先要apache 请求ssl证书的csr 一下是步骤: 重要注意事项 An Importan ...
- hdu 2859 (二维dp)
点击打开链接 题意: 给你一个n*n的矩阵,矩阵中只含有26个小写字母,求其中最大的对称矩阵的大小 当我们算到s[i][j]时,每次我们只需要将它上方的和右方的依次比较,看是否相同 注意这里不能只比较 ...
- hdu 3074 Multiply game(模板级线段树)
离机房关门还有十分钟,这点时间能干些什么?故作沉思地仰望星空,重新捋一下一天的学习进度,或者,砍掉一棵模板级线段树. 纯模板,就是把单点更新,区间求和改为单点更新,区间求积. 1A. #include ...
- Servlet容器模型(四)ServletConfig、ServletContext
这两天刚刚回顾了一下servlet中的配置对象ServletConfig.上下文对象ServletContext.多线程相关的知识点,做了一下笔记,如下: 一.Servlet配置对象(ServletC ...
- Android监听WebView滑动到底部
MainActivity如下: package cn.testwebview; import android.app.Activity; import android.graphics.Bitmap; ...
- nginx错误:unknown directive "锘? in F:\nginx/conf/nginx.conf:3
C:\Users\Administrator>d: D:\>cd D:\nginx-1.4.7 D:\nginx-1.4.7>start nginx.exe D:\nginx-1.4 ...
- SQL Server 2016 的「動態資料遮罩 (Dynamic Data Masking)」
一些特別注重資訊安全.個人資料的公司或產業 (如: 金融.保險業),通常「測試用資料庫」的資料,會加上「遮蔽:去識別化」的功能,避免個資外洩.以往必須自己撰寫 SQL 語句或 Stored Proce ...
- (四)python自带解释器(LDIE)的使用
什么是IDE? Integrated Development Environment(集成开发环境) 打个不恰当的比方,如果说写代码是制作一件工艺品,那IDE就是机床.再打个不恰当的比方,PS就是图片 ...
- hdu 2824 The Euler function(欧拉函数)
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...
- volatile(C# 参考)
本文档已存档,并且将不进行维护. volatile(C# 参考) 若要了解有关 Visual Studio 2017 RC 的最新文档,请参阅 Visual Studio 2017 RC 文档. vo ...