Read problems statements in Mandarin chinese, Russian and Vietnamese as well. 

Even though it was a little unexpected, Chef did it! He has finally opened a new restaurant!

As you all know, to make everything go well, Chef needs employees (co-chefs if you might say). Because Chef is a perfectionist, he planned to employ only chefs who are good at competitive progeamming. Hence, Chef asked for help from his friends Shahhoud and Said. Knowing that many people (such as Ahmad, Nour, Majd and Joud) will apply for the job, they decided to choose only the best appliers.

As the day of the employment came, people lined up in front of the restaurant applying for the job. Before accepting any appliers, Shahhoud and Said decided to make them answer a simple question, in order to determine which of them better deserves the job.

Given an array of N elements A_{1}, A_{2}, ..., A_{N}, each applier was asked to insert any K integers he wants to this array. Eventually, each applier will be asked to write down the median among all the elements in his resulting array. Many appliers asked for your help to determine what is the greatest median they can get after inserting any K elements they want?

Note that the median in an array is the element positioned at the center of the array after sorting it. E.g. the median in [2, 1, 5, 2, 4] is 2, and the median in [3, 3, 1, 3, 3] is 3.
 
------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases.

The first line of each test case contains two space separated integers N and K denoting the array length, and the number of elements to be inserted.

The second line of each test case contains N space separated integers A_{1}, A_{2}, ..., A_{N} denoting the elements of the array.

------ Output ------ 

For each test case output a single line, containing a single integer, indicating the greatest median the applier can obtain after inserting exactly K new elements into the given array.

------ Constraints ------ 

$1 ≤ T ≤ 100.$
$0 ≤ K < N ≤ 100.$
$0 ≤ A_{i} ≤ 1000.$
$N + K is guaranteed to be odd.$
 
----- Sample Input 1 ------ 
3
2 1
4 7
4 3
9 2 8 6
5 2
6 1 1 1 1
----- Sample Output 1 ------ 
7
9
1
----- explanation 1 ------ 
Test case $1$: A possible solution is to add element $9$ to the array. On sorting, the array becomes $[4, 7, 9]$. The element positioned at the center, after sorting, is $7$. It can be shown that the median of the array after inserting $1$ element cannot exceed $7$.

Test case $2$: A possible solution is to add elements $10, 20, $ and $30$ to the array. On sorting, the array becomes $[2, 6, 8, 9, 10, 20, 30]$. The element positioned at the center, after sorting, is $9$. It can be shown that the median of the array after inserting $3$ elements cannot exceed $9$.

Test case $3$: A possible solution is to add elements $2$ and $3$ to the array. On sorting, the array becomes $[1,1,1,1,2,3,6]$. The element positioned at the center, after sorting, is $1$. It can be shown that the median of the array after inserting $2$ elements cannot exceed $1$.

Source: codechef | Difficulty: EASY
Tags: Sorting

Constructive algorithms

Mathematics

Ad-hoc


Solutions:
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	task = list(map(int, input().split()))
	task = sorted(task)
	print(task[(n + m) // 2])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	print(a[(n + k) // 2])


t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	print(l[int((n + k) / 2)])


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr_s = arr.sort()
	print(arr[(n + k) // 2])


from statistics import median
goals = int(input())
for distractions in range(goals):
	(wife, life) = map(int, input().split())
	stress = list(map(int, input().split()))
	for aim in range(life):
		stress.append(max(stress) + 10)
	stress.sort()
	print(median(stress))


import math
T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	A.extend([A[-1] + 1] * K)
	L = A[(K + N) // 2]
	print(L)


from statistics import median
for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(b):
		l.append(max(l) + 10)
	l.sort()
	print(median(l))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	integers = list(map(int, input().split()))
	integers.sort()
	print(integers[(n + k) // 2])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	print(arr[(n + k) // 2])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = (n + k) // 2
	lst = list(map(int, input().split()))
	lst.sort()
	print(lst[a])


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	P = N + K
	print(A[P // 2])


x = int(input())
kkr = []
for th in range(0, x):
	f = str(input())
	yre = str(input())
	tc = f.split(' ')
	ll = yre.split(' ')
	opr = []
	for uuer in ll:
		opr.append(int(uuer))
	hnb = [opr]
	hnb.append(int(tc[-1]))
	kkr.append(hnb)
for xxz in kkr:
	xxz[0].sort()
	umt = xxz[0][0]
	ml = xxz[1]
	for tvb in range(0, len(xxz[0])):
		uyt = ml + len(xxz[0]) - 1 - tvb
		umre = tvb - 0
		redf = ml + tvb
		ffcx = len(xxz[0]) - 1 - tvb
		if uyt == umre or redf == ffcx:
			umt = xxz[0][tvb]
			continue
	print(umt)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if n - 1 == k:
		print(l[-1])
	else:
		print(l[(len(l) + k) // 2])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	maxi = max(l)
	for j in range(k):
		maxi += 1
		l.append(maxi)
	l.sort()
	mid = len(l) // 2
	print(l[mid])


t = int(input())
while t != 0:
	t = t - 1
	(n, k) = map(int, input().split())
	ans = (n + k) // 2
	arr = [int(i) for i in input().split()]
	arr.sort()
	print(arr[ans])


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	x = (N + K) // 2
	print(A[x])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	v = 0
	a.sort()
	a1 = m * [1]
	ab = a1 + a
	af = a + a1
	n = (n + m) // 2
	k = n
	print(max(ab[k], af[k]))


try:
	for _ in range(int(input())):
		(N, K) = map(int, input().split())
		L = sorted(map(int, input().split()))
		print(L[(N + K) // 2])
except:
	pass


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sorted(a)
	print(s[(n + k) // 2])


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = math.ceil((n + k) / 2)
	print(l[c - 1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	x = (n + k) // 2
	print(arr[x])


a = int(input())
for i in range(0, a):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	print(a[(n + m) // 2])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(c) for c in input().split()]
	a.sort()
	l = (n + k) // 2
	print(a[l])


for i in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	c = (N + K) // 2
	if K == N - 1:
		print(A[-1])
	else:
		print(A[c])


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l2 = list(map(int, input().split()))
	l2 = sorted(l2)
	print(l2[(n + m) // 2])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	mid = int((n + k) / 2)
	print(lst[mid])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mid = int((n + k) / 2)
	med = a[mid]
	print(med)


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	print(a[(n + k) // 2])


for _ in range(int(input())):
	(length, elements) = map(int, input().split())
	table = list(map(int, input().split()))
	table.sort()
	print(table[(length + elements) // 2])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	o = max(a)
	for i in range(1, k + 1):
		a.append(o + i)
	a.sort()
	u = len(a) // 2
	print(a[u])


import math as m
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	y = m.ceil((n + k) / 2)
	print(l[y - 1])


s = int(input())
for i in range(s):
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	x.sort()
	print(x[(n + k) // 2])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = max(a) + 1
	for i in range(0, k):
		a.append(c)
		c += 1
	a.sort()
	n = len(a)
	z = n // 2
	print(a[z])


import random
for i in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	for j in range(k):
		lst.append(max(lst) + j)
	lst2 = sorted(lst)
	for j in range(k):
		lst.append(random.randint)
	num = (n + k + 1) / 2
	print(lst2[int(num - 1)])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr)
	print(arr[(n + k) // 2])


for t in range(int(input())):
	(n, k) = map(int, input().split(' '))
	elem = list(map(int, input().split(' ')))
	elem.sort()
	mid = (len(elem) + k) // 2
	print(elem[mid])


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	array = sorted(list(map(int, input().split(' '))))
	median = (n + k + 1) // 2
	print(array[median - 1])


for i in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(l[(x + y) // 2])