In a class of N students, a class test was held. The i^{th} student scored A_{i} marks. It is also known that the scores of all students were distinct.

A student passes the test if their score is strictly greater than the passing mark. 
Given that exactly X students pass in the test, find the maximum value of the passing mark of the test.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains two space-separated integers N and X — the number of students in the class and the number of students that passed in the test.
- The next line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}, where the i^{th} integer denotes the marks of the i^{th} student.

------ Output Format ------ 

For each test case, output on a new line, the maximum value of the passing mark of the test.

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

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 100$
$1 ≤ X ≤ N$
$1 ≤ A_{i} ≤ 100$
- All elements of array $A$ are distinct.

----- Sample Input 1 ------ 
3
2 2
5 1
4 1
5 1 7 4
4 3
15 70 100 31

----- Sample Output 1 ------ 
0
6
30

----- explanation 1 ------ 
Test case $1$: Since both students pass the test, both students scored greater than passing marks. The maximum value of passing marks can be $0$, as both students have marks greater than $0$.

Test case $2$: Only one student passes the test. Thus, the third student has passed the test by scoring $7$ marks. The passing marks of the test is $6$.

Test case $3$: Since three students pass the test, students $2, 3,$ and $4$ scored greater than passing marks. The maximum value of passing marks can be $30$, three students have marks greater than $30$.

Difficulty: EASY
Tags: Complete search
Skill types: Complete search

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	z = list(map(int, input().split()))
	z.sort()
	print(z[x - y] - 1)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	i = list(map(int, input().split()))
	i.sort()
	print(i[a - b] - 1)
	t -= 1


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	print(a[-x] - 1)


def fin():
	return a[-x] - 1
for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	print(fin())


for i in range(int(input())):
	(n, x) = map(int, input().split())
	print(sorted(list(map(int, input().split())))[-x] - 1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	c.sort()
	print(c[-b] - 1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	for i in range(a - b):
		x.remove(min(x))
	print(min(x) - 1)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	for j in range(y - 1):
		l.remove(max(l))
	print(max(l) - 1)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if n == x:
		print(min(a) - 1)
	else:
		b = n - x
		c = a[b:]
		print(min(c) - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	arr = []
	for i in range(x):
		max1 = max(a)
		arr.append(max1)
		a.remove(max1)
		i -= 1
	min1 = min(arr)
	print(min1 - 1)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	z = list(map(int, input().split()))
	z.sort()
	print(z[x - y] - 1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if x == len(l):
		print(min(l) - 1)
	else:
		l.sort(reverse=True)
		print(l[x - 1] - 1)


t = int(input())
for i in range(t):
	(students, passed_students) = map(int, input().split())
	ai = list(map(int, input().split()))
	ai.sort()
	print(ai[students - passed_students] - 1)


def getarr():
	return list(map(int, input().split()))

def getinp():
	return map(int, input().split())

def main():
	for _ in range(int(input())):
		(n, x) = getinp()
		arr = getarr()
		if n == x:
			print(min(arr) - 1)
		else:
			arr.sort(reverse=True)
			for n in arr:
				x -= 1
				if x == 0:
					print(n - 1)
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = input().split()
	lst = []
	for i in a:
		lst.append(int(i))
	r = sorted(lst, reverse=True)
	print(r[x - 1] - 1)


for z in range(int(input())):
	(n, p) = [int(x) for x in input().split()]
	s = [int(x) for x in input().split()]
	s.sort()
	P_S = []
	for l in range(len(s) - 1, len(s) - p - 1, -1):
		P_S.append(s[l])
	P_S.sort()
	print(P_S[0] - 1)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = n - x
	if d == 0:
		print(min(a) - 1)
	else:
		a.sort()
		print(a[d] - 1)


T = int(input())
for i in range(T):
	(N, X) = map(int, input().split())
	m = list(map(int, input().split()))
	m.sort()
	print(m[N - X] - 1)


n = int(input())
for i in range(n):
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	b.sort()
	d = b[-a[1]] - 1
	print(d)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == x:
		print(min(l) - 1)
	else:
		for i in range(x):
			a = max(l)
			l.remove(a)
		print(a - 1)


def find_max_passing_mark(n, x, scores):
	sorted_scores = sorted(scores, reverse=True)
	x_score = sorted_scores[x - 1]
	passing_mark = max(0, x_score - 1)
	print(passing_mark)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	scores = list(map(int, input().split()))
	find_max_passing_mark(n, x, scores)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	marks = list(map(int, input().split()))
	for a in range(x - 1):
		marks.remove(max(marks))
	passed = max(marks) - 1
	print(passed)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lis = list(map(int, input().split()))
	if n == x:
		print(min(lis) - 1)
	else:
		for i in range(x):
			l = max(lis)
			lis.remove(l)
		print(l - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	b = n - x
	for i in range(b):
		a.pop()
	print(min(a) - 1)


for i in range(int(input())):
	(x, n) = map(int, input().split())
	l = list(map(int, input().strip().split()))
	l = sorted(l)
	l1 = l[::-1]
	print(l1[n - 1] - 1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == x:
		print(min(a) - 1)
	elif x == 1:
		print(max(a) - 1)
	else:
		a.sort()
		print(a[n - x] - 1)


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	lst = [int(i) for i in input().strip().split()][0:N]
	lst.sort(reverse=True)
	students_failed = N - X
	cut_off = lst[-(students_failed + 1)]
	print(cut_off - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(l[-x] - 1)


t = int(input())
while t != 0:
	(n, x) = map(int, input().split(' '))
	clas = list(map(int, input().split(' ')))
	clas.sort()
	print(clas[n - x] - 1)
	t -= 1


for i in range(int(input())):
	(a, b) = map(int, input().split(' '))
	numbers = [int(x) for x in input().split()]
	numbers = numbers[:a]
	minmarks = sorted(set(numbers))[-b]
	print(minmarks - 1)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = sorted(list(map(int, input().split())))
	x = x[::-1][b - 1:]
	print(x[0] - 1)


for i in range(int(input())):
	(N, X) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	p = len(arr) - X
	res = arr[p] - 1
	print(res)


T = int(input())
for _ in range(T):
	line = input().split(' ')
	N = int(line[0])
	X = int(line[1])
	lst = sorted(list(map(int, input().split(' '))))
	print(lst[-X] - 1)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	print(l[a - b] - 1)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	print(a[-x] - 1)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c = sorted(a)
	d = n - x
	if x == 0:
		print(max(c) + 1)
	else:
		print(c[d] - 1)


t = int(input())
for _ in range(t):
	(n, p) = map(int, input().split())
	a = list(map(int, input().split()))
	l = a
	for i in range(p - 1):
		l.remove(max(l))
	cm = max(l) - 1
	print(cm)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	g = l[::-1]
	print(g[b - 1] - 1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(l[n - x] - 1)


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sorted(a)
	print(b[x - y] - 1)


def code():
	cases = int(input())
	for _ in range(cases):
		(num_students, num_passed) = map(int, input().split(' '))
		marks = list(map(int, input().split(' ')))
		marks.sort(reverse=True)
		sorted_marks = marks
		passed_scores = []
		for i in range(num_passed):
			passed_scores.append(sorted_marks[i])
		min_passed_score = min(passed_scores)
		passing_mark = min_passed_score - 1
		print(passing_mark)
code()


t = int(input())
while t:
	(a, b) = input().split()
	li = list(map(int, input().split()))
	a = int(a)
	b = int(b)
	li.sort(reverse=True)
	print(li[b - 1] - 1)
	t -= 1


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == x:
		print(min(a) - 1)
	else:
		a.sort(reverse=True)
		print(a[x - 1] - 1)


T = int(input())
for i in range(T):
	(N, X) = [int(x) for x in input().split()]
	array = list((int(x) for x in input().split()))
	array.sort()
	array.reverse()
	print(array[X - 1] - 1)


T = int(input())
for i in range(T):
	(N, X) = map(int, input().split())
	LN = list(map(int, input().split()))
	LN.sort()
	length = len(LN)
	print(LN[length - X] - 1)


t = int(input())
for fsfi in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	print(arr[n - x] - 1)


t = int(input())
for i in range(t):
	(x, y) = [int(s) for s in input().split()]
	n = [int(s) for s in input().split()]
	n.sort(reverse=True)
	print(n[y - 1] - 1)


for i in range(int(input())):
	(n, x) = map(int, input().split(' '))
	marks = list(map(int, input().split(' ')))
	marks.sort(reverse=True)
	print(marks[x - 1] - 1)


t = int(input())
for i in range(0, t):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	print(A[n - x] - 1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = len(a) - x
	print(a[c] - 1)