Mahmoud and Ehab and the MEX
2017-09-23 20:49
344 查看
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.
Example
Input
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.
题解:我们记比x小的数有k个,与x相等的数有t个,则ans=x-k+t 。
Code:
var n,x,i,ans:longint; a:array[1..1000] of longint; procedure sort(l,r:longint); var i,j,x,y:longint; begin i:=l;j:=r;x:=a[(l+r) div 2]; repeat while a[i]<x do inc(i); while a[j]>x do dec(j); if not(i>j) then begin y:=a[i];a[i]:=a[j];a[j]:=y; inc(i);dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin readln(n,x); for i:=1 to n do read(a[i]); sort(1,n); for i:=1 to n do if a[i]<x then inc(ans); ans:=x-ans; for i:=1 to n do if a[i]=x then inc(ans); writeln(ans); end.
相关文章推荐
- codeforces 862A 之 Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) A. Mahmoud and Ehab and the MEX(思路)
- Codeforces - 862A Mahmoud and Ehab and the MEX
- A. Mahmoud and Ehab and the MEX
- Codeforces Round #435 (Div. 2) 之Mahmoud and Ehab and the MEX
- Codeforces Round #435 A. Mahmoud and Ehab and the MEX
- codeforces 862A Mahmoud and Ehab and the MEX
- Codeforces --- Mahmoud and Ehab and the MEX
- CodeForces 862A Mahmoud and Ehab and the MEX
- Codeforces 862A Mahmoud and Ehab and the MEX
- codeforces 862A Mahmoud and Ehab and the MEX
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
- codeforces 862B B. Mahmoud and Ehab and the bipartiteness
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor
- Codeforces Round #435 (Div. 2) B. Mahmoud and Ehab and the bipartiteness
- Codeforces Round #435 (Div. 2) E. Mahmoud and Ehab and the function
- Codeforces Round #435 (Div. 2)B. Mahmoud and Ehab and the bipartiteness(补)
- 【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness
- codeforces 862B (二分图 dfs )之 Mahmoud and Ehab and the bipartiteness
- Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor