首页 > 其他分享 >CodeForces - 659C Tanya and Toys (map&模拟)

CodeForces - 659C Tanya and Toys (map&模拟)

时间:2023-04-19 15:35:02浏览次数:52  
标签:map CodeForces collection Tanya toys new include types

CodeForces - 659C Tanya and Toys

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

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 exceedm.

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 7 1 3 4 Output 2 2 5 Input 4 14 4 6 12 8 Output 4 7 2 3 1 //题意: 有1e9种商品,第i件商品的价格为i元,你已经有了n件商品,现在你有m元,问你还能最多买多少种其他的商品? //思路: 还是不怎么会用map啊,map太强大了,看了大神的才知道,得活学活用。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 100010 
#define M 1000000007
using namespace std;
map<int,bool>mm;
int main()
{
	int t,n,m,i,j,k;	
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		mm.clear();
		while(n--)
		{
			scanf("%d",&k);
			mm[k]=true;
		}
		t=1;
		queue<int>q;
		while(m)
		{
			if(mm[t])
			{
				t++;
				continue;
			}
			if(m-t>=0)
			{
				m-=t;
				q.push(t);
				t++;
			}
			else
				break;
		}
		printf("%d\n",q.size());
		k=0;
		while(!q.empty())
		{
			if(k)
				printf(" ");
			printf("%d",q.front());
			q.pop();k++;
		}
		printf("\n");
	}
	return 0;
}

标签:map,CodeForces,collection,Tanya,toys,new,include,types
From: https://blog.51cto.com/u_16079508/6206439

相关文章

  • CodeForces - 367B Sereja ans Anagrams (map)
    CodeForces-367BSerejaansAnagramsTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionSerejahastwosequences a and b andnumber p.Sequence a consistsof n integers a1, a......
  • CodeForces - 368C Sereja and Algorithm (找规律&模拟)
    CodeForces-368CSerejaandAlgorithmTimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionSerejalovesallsortsofalgorithms.Hehasrecentlycomeupwithanewalgorithm,whichreceiv......
  • CodeForces - 616E Sum of Remainders (数论)大数取余求和 好题
    CodeForces-616ESumofRemaindersTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionCalculatethevalueofthesum: nmod1 + nmod2 + nmod3 +...+ nmodm.Astheresultcanbeve......
  • 获取java HashMap 的容量和阈值
      publicstaticvoidmain(String[]args)throwsException{HashMap<Integer,Integer>m=newHashMap<>(9);Class<?>mapType=m.getClass();Fieldthreshold=mapType.getDeclaredField("threshold");......
  • Educational Codeforces Round 113 (Rated for Div. 2)
    题目链接B核心思路这个题目我觉得很好。首先分析下吧,如果有人需要执行操作二那么我们肯定就是给他们都打上平局是最优的。那么如果有人需要执行操作一呢,那么我们就可以把这些需要执行操作1的都搞一起。然后是他们成一个环。这样肯定就保证了每个人都会赢上一次。C核心思路......
  • 4月18日set与map的学习
    之前学习过string,list,vector,deque,和两种适配器queue和stack,这些都是线性表的数据结构;而今天学习的map和set他们的底层是二叉搜索树,或者平衡二叉搜索树。首先是set她没有键值对,并且不能出现重复元素,比如当插入两个一时,他只会插入一个一,所以可以用作数组去重。 比如上图当插......
  • Codeforces Round 866 (Div. 2)
    A.Yura'sNewName一个简单的dp,状态是\(f[i][0/1]\)表示前\(i\)位变成合法的且最后一位是^或_的最小代价。如果是_只能从^转移过来,如果是^则都可以转移过来#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ strings; cin>>s; intn=s.size(); if(n=......
  • 如何计算 目标检测任务的 AP 以及 mAP 指标?
    AP50:50的的意思是IOU的阈值是0.5。先算AP,AP是针对某一类的,表示不同置信度下的PR值的平均,也就是通过不同置信度得到一条PR曲线,曲线下的面积就是AP。这里的置信度是模型输出的条件概率,即是该类的条件下的概率。比如对于persion这一类,模型经过NMS得到一些......
  • Redis高级 哈希类型、列表类型、集合类型、有序集合(zset)、慢查询、pipeline与事务
    哈希类型###1---hget,hset,hdelhgetkeyfield#获取hashkey对应的field的value时间复杂度为o(1)hsetkeyfieldvalue#设置hashkey对应的field的value值时间复杂度为o(1)hdelkeyfield#删除hashkey对应的field的值时间复杂度为o(1)#测试hsetuser:1:infoage......
  • 【Redis】哈希类型 列表类型 集合类型 有序集合 慢查询 pipeline与事务 发布订阅 Bitm
    目录昨日回顾今日内容1哈希类型2列表类型3集合类型4有序集合(zset)5慢查询6pipeline与事务7发布订阅8Bitmap位图9HyperLogLog作业昨日回顾#1redis介绍 -特性#速度快:10wops(每秒10w读写),数据存在内存中,c语言实现,单线程模型#持久化:rdb和aof#多种数据结......