Sam Height <HSBC>

3.8

8 votes
Algorithms, Easy, Implementation, Merge Sort, Sorting, easy
Problem

Sam among his friends wants to go to watch a movie in Armstord Cinema.
There is something special about Armstord cinema whenever people come in the group here. They will get seats accordingly their heights. Sam as a curious guy always wants to sit in the middle as cinema has the best view from the middle.
Now, Sam as the leader of his group decides who will join him for the movie.
Initially, he has N1 friends with him (N including him).
You are given N1 numbers that represent the heights of Sam's friends.
You are given the height of Sam as well.

Now, Sam can do two operations:
1. He can call a new friend of height H.
2. He can cancel any of his friend invitations.

Each operation will cost him a unit time.
He wants to do this as soon as possible.

Input format

  • The first line contains T, where T is the test case.
  • Each test case contain two lines,
    • The first line contains two space-separated integer N, S where N is the total number of Sam's friend and S is Sam height.
    • The second line contains N space-separated integers that represent the height of Sam's friend.


Output format
Print the required answer for each test case in a new line.

Constraints

1T1001N1051Ar[i]109

Note:

  • Sam should always sit in middle and there's an equal number of persons in his left and right.
  • Height of Sam is always unique.      
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In first test case :
We can cancel invitation of person of height 4 (Cost = 1)
In second Test Case:
We can invite person with height 4 (Cost =1)

Editor Image

?