Codeforces

来源:互联网 发布:西村由纪江 知乎 编辑:程序博客网 时间:2024/06/09 21:09

A. Mahmoud and Ehab and the MEX

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 integersevil if theMEX 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, theMEX of the set{0, 2, 4} is1 and theMEX of the set{1, 2, 3} is0 .

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 andx (1 ≤ n ≤ 100,0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desiredMEX.

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

Output

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

Examples
Input
5 30 4 5 6 7
Output
2
Input
1 00
Output
1
Input
5 01 2 3 4 5
Output
0
Note

For the first test case Dr. Evil should add 1 and2 to the set performing2 operations.

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

In the third test case the set is already evil.



题意:给你一个集合和一个邪恶数字M,问你最少要多少个操作,才能使得M是这个集合里最小的非负整数。操作包括,删除数字和添加数字。


解题思路:由于集合很小,直接暴力计算即可。详细看代码注释。其实就是看看集合里有多少个比M小的数。然后简单算算就可以了。


#include<iostream>#include<deque>#include<memory.h>#include<stdio.h>#include<map>#include<string.h>#include<algorithm>#include<vector>#include<math.h>#include<stack>#include<queue>#include<set>using namespace std;typedef long long int ll;int a[200];int main(){        int n,m;    cin>>n>>m;        for(int i=0;i<n;i++)        cin>>a[i];        sort(a,a+n);//可忽略……        int i;    int num=0;        //计算集合里比M小的数有多少个,直接枚举每一个数看看集合里有没有    for(i=0;i<m;i++){        for(int j=0;j<n;j++){            if(a[j]==i){                num++;            }        }    }        //看看有没有跟M大小一个的数,有的话需要一个删除操作。这里aaa要么0要么1.    int aaa=0;    for(int j=0;j<n;j++){        if(a[j]==m){            aaa++;        }    }        //答案    cout<<m-num+aaa<<endl;                        return 0;}