CF A. Dreamoon and Ranking Collection

A. Dreamoon and Ranking Collection

Example:

input
5
6 2
3 1 1 5 7 10
1 100
100
11 1
1 1 1 1 1 1 1 1 1 1 1
1 1
1
4 57
80 60 40 20

output:
5
101
2
2
60

代码:

#include<iostream>
using namespace std;
int main()
{
	int time;
	cin>>time;
	for(int t=0;t<time;t++)
	{
		int n,x,flag[1005]={0},ans,tmp;
		cin>>n>>x;
		for(int i=0;i<n;i++){
			cin>>tmp;
			flag[tmp]=1;
		}
		for(int i=1;;i++)
		{
			if(flag[i]==0){
				flag[i]=1;
				x--;
			}
			if(x==0)break;
		}
		for(int i=1;i<1005;i++)if(flag[i]==0){
			ans=i-1;
			break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

猜你喜欢

转载自www.cnblogs.com/LiangYC1021/p/12640251.html