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

Sergey has made N measurements. Now, he wants to know the average value of the measurements made.

In order to make the average value a better representative of the measurements, before calculating the average, he wants first to remove the highest K and the lowest K measurements. After that, he will calculate the average value among the remaining N - 2K measurements.

Could you help Sergey to find the average value he will get after these manipulations?

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains two space-separated integers N and K denoting the number of measurements and the number of the greatest and the lowest values that will be removed.
The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the measurements. 

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

For each test case, output a single line containing the average value after removing K lowest and K greatest measurements.
Your answer will be considered correct, in case it has absolute or relative error, not exceeding 10^{-6}.

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

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{4}$
$0 ≤ 2K < N$
$-10^{6} ≤ A_{i} ≤ 10^{6}$

------ Subtasks ------ 

$Subtask #1 (50 points): K = 0$
$Subtask #2 (50 points): no additional constraints$

----- Sample Input 1 ------ 
3

5 1

2 9 -10 25 1

5 0

2 9 -10 25 1

3 1

1 1 1
----- Sample Output 1 ------ 
4.000000

5.400000

1.000000
----- explanation 1 ------ 
Example case 1. After removing 1 greatest and 1 lowest measurement, we get the set {2, 9, 1}. The average value in this set is (2+9+1)/3=4.
Example case 2. The average value in the set {2, 9, -10, 25, 1} is (2+9-10+25+1)/5=5.4.
Example case 3. After removing the 1 largest and smallest measurements, Sergey will be left with only one measurement, i.e. 1. Average of this is 1 itself.

Source: codechef | Difficulty: EASY
Tags: Sorting

Mathematics


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lst = sorted(list(map(int, input().split())))
	avg = sum(lst[k:n - k]) * 1.0 / (n - 2 * k)
	print(avg)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(sum(l[k:n - k]) * 1.0 / (n - 2 * k))


def average_after_manipulations(n, k, measurements):
	measurements.sort()
	return sum(measurements[k:n - k]) / (n - 2 * k)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	measurements = list(map(int, input().split()))
	print('{:.6f}'.format(average_after_manipulations(n, k, measurements)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if k == 0:
		print(f'{sum(arr) / n: .6f}')
	else:
		print(f'{sum(arr[k:n - k]) / (n - 2 * k): .6f}')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	s = sum(l[k:n - k]) * 1.0 / (n - 2 * k)
	print(s)


for _ in range(int(input())):
	(buddyluuu, janu) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	sin = sum(l[janu:buddyluuu - janu]) * 1.0 / (buddyluuu - 2 * janu)
	print(sin)


for i in range(int(input())):
	(X, Y) = map(int, input().split())
	arr1 = input().split()
	arr = [int(val) for val in arr1]
	arr.sort()
	avg = 0
	count = 0
	for i in range(Y, len(arr) - Y):
		count += 1
		avg += arr[i]
	print(avg / count)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	measurements = list(map(int, input().split()))
	measurements.sort()
	sum_measurements = sum(measurements[k:n - k])
	avg = sum_measurements / (n - 2 * k)
	print('{:.6f}'.format(avg))


n = int(input())
for i in range(n):
	(N, K) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	avg = sum(arr[K:N - K]) * 1.0 / (N - 2 * K)
	print(avg)


t = int(input())
for i in range(t):
	n_k = input().split(' ')
	measurements = input().split(' ')
	for j in range(int(n_k[0])):
		measurements[j] = int(measurements[j])
	measurements.sort()
	print(sum(measurements[int(n_k[1]):len(measurements) - int(n_k[1])]) / (int(n_k[0]) - 2 * int(n_k[1])))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	k1 = 2 * k
	l.sort()
	l1 = l[k1 // 2:n - k1 // 2]
	print(sum(l1) / (n - 2 * k))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = sum(a[k:n - k]) / (n - 2 * k)
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = sorted(list(map(int, input().split())))
	s = sum(c[b:a - b]) / (a - 2 * b) * 1.0
	print(s)


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	while k:
		t = len(a)
		a.pop(t - 1)
		a.pop(0)
		k -= 1
	l = len(a)
	s = sum(a)
	print(float(s / l))


t = int(input())
while t:
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	s = 0
	for j in range(K, len(A) - K):
		s += A[j]
	print(s / (len(A) - K * 2))
	t = t - 1


for k in range(int(input())):
	(a, b) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	del arr[:b]
	del arr[len(arr) - b:]
	print(sum(arr) / (a - 2 * b))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	deno = n - 2 * k
	while k:
		a.pop(len(a) - 1)
		a.pop(0)
		k -= 1
	summ = sum(a)
	print(summ / deno)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	s = sum(l[y:x - y]) / (x - 2 * y)
	print('{0:.6f}'.format(s))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l2 = l[k:n - k]
	print(sum(l2) / (n - 2 * k))


n = int(input())
for i in range(n):
	(N, K) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	avg = sum(arr[K:N - K]) / len(arr[K:N - K])
	print(avg)


cases = int(input())
for i in range(cases):
	(N, K) = map(int, input().split())
	measurements = list(map(int, input().split()))
	measurements.sort()
	for j in range(K):
		measurements.pop()
		measurements.pop(0)
	sum = 0
	for d in measurements:
		sum += d
	print(sum / (N - 2 * K))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l1.sort()
	l2 = l1[k:n - k]
	print(sum(l2) / len(l2))


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	s = 0
	del a[:k]
	del a[len(a) - k:]
	print(sum(a) / (n - 2 * k))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	li1 = li[b:len(li) - b]
	val = sum(li1) / len(li1)
	print('{:.6f}'.format(val))


T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	print(sum(A[K:N - K]) / (N - 2 * K))


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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	avg = sum(l[k:n - k]) * 1.0 / (n - 2 * k)
	print(avg)


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


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	for j in range(b):
		l.pop(0)
		l.pop(-1)
	s = sum(l) * 1.0 / (a - 2 * b)
	print(s)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(m):
		x = l[0]
		y = l[-1]
		l.pop(0)
		l.pop(-1)
	print(float(sum(l) / len(l)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	L = sorted(list(map(int, input().split())))
	for _ in range(k):
		L.pop(0)
		L.pop(-1)
	print(sum(L) / len(L))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if k != 0:
		l = l[k:-k]
	print(float(sum(l)) / len(l))


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A = sorted(A)
	for i in range(K):
		A.pop(0)
		A.pop(-1)
	print('%.6f' % (sum(A) / len(A)))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	avg = sum(A[K:N - K]) / (N - 2 * K)
	print(avg)


testcases = int(input())
for _ in range(testcases):
	(n, m) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	for i in range(m):
		array.pop()
		array.pop(0)
	sum_ = sum(array)
	avg = sum_ / (n - 2 * m)
	print(avg)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	c.sort()
	c = c[b:a - b]
	d = sum(c) / len(c)
	print(d)


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


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


for x in range(int(input())):
	(N, K) = map(int, input().split())
	l = list(map(int, input().split()))
	if len(l) <= K * 2:
		print(0)
		continue
	l.sort()
	for x in range(K):
		l.pop(0)
		l.pop()
	print(sum(l) / len(l))


from statistics import mean
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	A = A[K:-K] if K != 0 else A
	print(mean(A))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = [int(x) for x in input().split()]
	lst.sort()
	sum = 0
	for i in range(k, n - k):
		sum += lst[i]
	avg = sum / (n - 2 * k)
	print('{:.6f}'.format(avg))


def mean(a):
	s = 0
	for i in a:
		s += i
	return s / len(a)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = list(map(int, input().split()))
	m.sort()
	if k == 0:
		pass
	else:
		m = m[k:-k]
	print(mean(m))


def average_after_removal(n, k, measurements):
	measurements.sort()
	sum_measurements = sum(measurements[k:n - k])
	avg = sum_measurements / (n - 2 * k)
	return avg

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		measurements = list(map(int, input().split()))
		avg = average_after_removal(n, k, measurements)
		print('{:.6f}'.format(avg))
main()


for i in range(int(input())):
	(ac, b) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	while b:
		a.pop()
		a.pop(0)
		b -= 1
	su = sum(a)
	if ac != len(a):
		print('{:.6f}'.format(su / len(a)))
	else:
		print('{:.6f}'.format(su / ac))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a = a[k:n - k]
	m = sum(a) / len(a)
	if len(a) == 0:
		print(0)
	else:
		print('{0:.6f}'.format(m))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if k == 0:
		print(sum(a) / n)
	else:
		print(sum(a[k:-k]) / (n - 2 * k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l = l[k:n - k]
	a = sum(l) / (n - 2 * k)
	print(a)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	s = sum(l[K:N - K]) * 1.0 / (N - 2 * K)
	print(s)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	su = 0
	for j in range(k, n - k):
		su += a[j]
	print('{:.6f}'.format(su / (n - 2 * k)))


for i in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	del A[:K]
	P = A[::-1]
	del P[:K]
	s = 0
	for j in P:
		s += j
	P1 = format(s / len(P), '5f')
	print(P1)