Codeforces --- Mahmoud and Ehab and the MEX

来源:互联网 发布:数据存储安全 编辑:程序博客网 时间:2024/06/03 21:15

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 ≤ 1000 ≤ 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.

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

输入n,x

n代表 a【i】的长度。

s输出经过 多少次操作可是使得最小未出现非负整数是x

每次操作可以拿走一个数字或者添加一个数字

小于等于x 的所有的数字我们都给标记

并且我们要知道x 的出现次数 ///也就是我们要拿走的操作

如果前边没有出现的数字我们要增加上。

operator = 添加 + 拿走的X

#include<bits/stdc++.h>using namespace std;int vis[10005];int main(){    int n,m;    while(~scanf("%d%d",&n,&m))    {        memset(vis,0,sizeof(vis));        for(int i=0; i<n; i++)        {            int x;            scanf("%d",&x);            if(x<=m&&x>=0)            {                vis[x]++;            }        }        int res=0;        for(int i=0; i<m; i++)        {            if(vis[i]==0)res++;        }        res+=vis[m];        printf("%d\n",res);    }}


原创粉丝点击