首页 技术 正文
技术 2022年11月11日
0 收藏 790 点赞 4,057 浏览 1993 个字

传送门:CF-862A

A. Mahmoud and Ehab and the MEXtime limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.

Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn’t exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .

Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?

Input

The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX.

The second line contains n distinct non-negative integers not exceeding 100 that represent the set.

Output

The only line should contain one integer — the minimal number of operations Dr. Evil should perform.

Examplesinput

5 3
0 4 5 6 7

output

2

input

1 0
0

output

1

input

5 0
1 2 3 4 5

output

0

Note

For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.

For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.

In the third test case the set is already evil.

思路:先排序,然后求Mex。与x进行比较,如果mex=x,输出0;如果mex>x,直接去掉x,所以输出1;mex<x时,向数列中填数直到mex>x或者mex=0,输出操作的次数。需要注意的是,如果数位不足,mex的最大值依然小于x,需要额外判断。

 #include<iostream>
using namespace std; int main()
{
int k;
int re;
int rec;
int mex;
int temp;
int n,x;
int a[];
cin>>n>>x;
for (int i=; i<n; i++) cin>>a[i];
for (int i=; i<n; i++)
{
for (int j=i+; j<n; j++)
{
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
} mex=a[n-]+;
re=n-;
for(int i=; i<n; i++)
{
if (a[i]!=i)
{
mex=i;
re=i-;
break;
}
} if (mex==x) cout<<;
else if (mex>x) cout<<;
else
{
rec=;
while(mex<x&&mex!=a[n-]+)
{
rec++;
int q=mex+;
re++;
k=re;
re=n-;
mex=a[n-]+;
for(int i=k;i<n;i++)
{
if(a[i]!=q)
{
re=i-;
mex=q;
break;
}
q++;
}
}
if(mex==x) cout<<rec;
else if(mex>x) cout<<rec+;
else cout<<(x-mex)+rec;
} return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290