description: You are given an integer array a_1, a_2, ..., a_n and integer k.
  
  In one step you can 
  
    * either choose some index i and decrease a_i by one (make a_i = a_i - 1); 
    * or choose two indices i and j and set a_i equal to a_j (make a_i = a_j). 
  
  
  
  What is the minimum number of steps you need to make the sum of array ∑_{i=1}^{n}{a_i} ≤ k? (You are allowed to make values of array negative).
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
  
  The first line of each test case contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ k ≤ 10^{15}) — the size of array a and upper bound on its sum.
  
  The second line of each test case contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the array itself.
  
  It's guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, print one integer — the minimum number of steps to make ∑_{i=1}^{n}{a_i} ≤ k.
  
  Example
  
  Input
  
  
  4
  1 10
  20
  2 69
  6 9
  7 8
  1 2 1 3 1 2 1
  10 1
  1 2 3 1 2 6 1 6 8 10
  
  
  Output
  
  
  10
  0
  2
  7
  
  Note
  
  In the first test case, you should decrease a_1 10 times to get the sum lower or equal to k = 10.
  
  In the second test case, the sum of array a is already less or equal to 69, so you don't need to change it.
  
  In the third test case, you can, for example: 
  
    1. set a_4 = a_3 = 1; 
    2. decrease a_4 by one, and get a_4 = 0. 
  
  As a result, you'll get array [1, 2, 1, 0, 1, 2, 1] with sum less or equal to 8 in 1 + 1 = 2 steps.
  
  In the fourth test case, you can, for example: 
  
    1. choose a_7 and decrease in by one 3 times; you'll get a_7 = -2; 
    2. choose 4 elements a_6, a_8, a_9 and a_{10} and them equal to a_7 = -2. 
  
  As a result, you'll get array [1, 2, 3, 1, 2, -2, -2, -2, -2, -2] with sum less or equal to 1 in 3 + 4 = 7 steps.
solution: import bisect
  
  mod = 10 ** 9 + 7
  eps = 10 ** -9
  
  
  def __gcd(a, b):
  	return a if b == 0 else __gcd(b, a % b)
  	
  
  def __lcm(a, b):
  	return a * b / __gcd(a, b)
  
  
  def __fact(n):
  	return 1 if n == 1 else n * __fact(n - 1)
  
  
  def __mex(a):
  	mex = 0
  	a.sort()
  	for x in a:
  		if x <= mex:
  			mex += 1
  		else:
  			break
  	return mex
  
  def __dist(x1, y1, x2, y2):
  	return (x1 - x2) ** 2 + (y1 - y2) ** 2
  
  def __getprimes(n):
      isprime = [True for i in range(n + 1)]
      primes = []
       
      for i in range(2, n + 1):
          if isprime[i]:
              for j in range(i * i, n + 1, i):
                  isprime[j] = False
      for i in range(2, n + 1):
          if isprime[i]:
              primes.append(i)
      return primes
  
  def __modInverse(a, m):
      
      m0 = m
      y = 0
      x = 1
      if (m == 1):
          return 0
      
      while(a > 1):
      	q = a // m
      	t = m
      	m = a % m
      	a = t
      	t = y
      	y = x - q * y
      	x = t
      if (x < 0):
      	x = x + m0
      return x
      
      
      
  def __isprime(n):
  	if n < 2:
  		return False
  	i = 2
  	while i * i <= n:
  		if n % i == 0:
  			return False
  		i += 1
  	return True
  	
  def __cntprimediv(n):
  	ret = 0
  	x = n
  	i = 2
  	while i * i <= x:
  		while n % i == 0:
  			n //= i
  			ret += 1
  		i += 1
  	if n > 1:
  		ret += 1
  	return ret
  	
  def __primefactors(n):
  	ret = []
  	x = n
  	i = 2
  	while i * i <= x:
  		while n % i == 0:
  			ret.append(i)
  			n //= i
  		i += 1
  	if n > 1:
  		ret.append(n)
  	return ret
  	
  
  def __sumdigit(n):
  	ret = 0
  	while n > 0:
  		ret += n % 10
  		n //= 10
  	return ret
  
  def __zfunc(s):
  	n = len(s)
  	z = [0 for i in range(n)]
  	l = 0
  	r = 0
  	for i in range(1, n):
  		if r >= i:
  			z[i] = min(z[i - l], r - i + 1)
  		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
  			z[i] += 1
  		if i + z[i] - 1 > r:
  			l = i
  			r = i + z[i] - 1
  	return z
  	
  	
  def __to(n, x):
  	ret = ''
  	while n > 0:
  		q = n % x
  		if q < 10:
  			ret += str(q)
  		else:
  			ret += chr(q - 10 + ord('a'))
  		n //= x
  	return ret[::-1]
  	
  	
  def solve(t):
  	n, k = map(int, input().split())
  	a = list(map(int, input().split()))
  	a.sort()
  	ans = 0
  	mn = a[0]
  	S = sum(a)
  	if S > k:
  		ans = a[0] - (k - (S - a[0]))
  		S = S - a[0]
  		cnt = 0
  		for i in range(n - 1, 0, -1):
  			S -= a[i]
  			cnt += 1
  			l = (k - S) // (cnt + 1)
  			if l > a[0]:
  				l = a[0]
  			ans = min(ans, cnt + a[0] - l)
  		
  	if n == 1 and a[0] > k:
  		ans = a[0] - k
  	print(ans)
  t = 1
  t = int(input())
  
  
  for i in range(t):
  	solve(i + 1)