Given an unsorted array **A[]** of** distinct integers** and size **N**, and an element **X**, you need to find the **Minimum Number of Elements** required to be added to this array so the new median of array becomes X.

Median of array is middle element of array in its sorted form. For odd number of elements N it is the element at position (N-1)/2. For even number of elements N, it is (A[N/2] + A[(N/2) - 1])/2.

**Input:** The first line contains number of testcases **T.** Every testcase consists of 2 lines, first line contains **N** - no of element of arrays and **X**, and second line contains Array elements in *unsorted* manner.

**Output:** You need to find total number of elements to be added to array so that the new median becomes equal to X.

**Constraints:**

1 <= **T** <= 100

1 <= **N** <= 10^{6}

1 <= **X** <= 10^{6}

1 <= **A[i]** <= 10^{6}

**Example:
Input: **

2

6 30

10 20 30 100 150 200

5 50

10 20 30 100 150

1

1

**Explanation:
Testcase 1: **Only 1 element before 30 is required to be added to the array, to make median of array 30.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

cs_abhi | 102 |

PiyushPandey4 | 100 |

codefundo | 95 |

kya_bolti_public | 93 |

masterishaan19 | 74 |

PiyushPandey4 | 916 |

john_wick | 765 |

ASWATHAMA | 565 |

UsfShilpa | 556 |

akhyasharma01 | 547 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.