Sam Height <HSBC>
Practice
3.8 (8 votes)
Algorithms
Easy
Implementation
Merge sort
Sorting
Easy
Problem
64% Success 4439 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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 \(N-1\) friends with him (\(N\) including him).
You are given \(N-1\) 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

\(1 \leq T \leq 100 \\ 1 \leq N \leq 10^5 \\ 1\leq Ar[i] \leq 10^9\)

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.      

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
194 votes
Tags:
AlgorithmsApprovedEasyOpenReady
Points:20
3 votes
Tags:
ImplementationSortingAlgorithms,2D dynamic programming
Points:20
22 votes
Tags:
ApprovedEasyMathOpenSorting