A bulb company claims that the average lifetime of its bulbs is at least X units.

The company ran a test on N bulbs. You are given the lifetime of N-1 of these bulbs. What is the minimum non-negative integer value of lifetime the remaining bulb can have, such that the claim of the company holds true?

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

- The first line contains a single integer T - the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers N and X - denoting the number of test bulbs and the minimum average lifetime of bulbs in the company's claim.
- The second line of each test case contains N - 1 space-separated integers A_{1}, A_{2}, \dots, A_{N-1} denoting the lifetimes of N-1 of the test bulbs.

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

For each testcase, output the minimum non-negative integer value of lifetime the remaining bulb can have such that the claim of the company holds true.

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

$1 ≤ T ≤ 100$
$2 ≤ N ≤ 100$
$0 ≤ A_{i} ≤ 1000$
$1 ≤ X ≤ 1000$

----- Sample Input 1 ------ 
3
3 4
1 5
4 2
5 8 6
3 1000
0 0

----- Sample Output 1 ------ 
6
0
3000

----- explanation 1 ------ 
Let $Y$ denote the value of the lifetime of the remaining bulb.

Test case 1: The remaining bulb must have lifetime no less than $6$ units. The average lifetime with $Y = 6$ is $\frac{(1+5+6)}{3} = 4 ≥ X$. It can be proven that for any non-negative integer value of $Y < 6$ it is not possible to have an average lifeftime of at least $X = 4$.

Test case 2: The average lifetime with $Y = 0$ is $\frac{(5+8+6+0)}{4} = 4.75 ≥ X$. Thus the minimum non negative value which satisfies the condition is $Y = 0$.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = a * b - sum(c)
	if d > 0:
		print(d)
	else:
		print(0)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	summ = 0
	for i in a:
		summ += i
	num = x * n - summ
	if num > 0:
		print(num)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	y = n * x - sum(a)
	if y > 0:
		print(y)
	else:
		print(0)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	for i in range(len(l)):
		sum = sum + l[i]
	c = x * n - sum
	if c >= 0:
		print(c)
	else:
		print(0)


n = int(input())
for _ in range(n):
	(N, X) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	lifetime = X * (len(A) + 1)
	for i in range(len(A)):
		lifetime -= A[i]
	if lifetime < X:
		print(0)
	else:
		print(lifetime)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	m = list(map(int, input().split()))
	s = n * x - sum(m)
	if s > 0:
		print(s)
	else:
		print(0)


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum1 = sum(arr)
	k = N * X - sum1
	if k < 0:
		print(0)
	else:
		print(k)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = input().split()
	s = 0
	for j in a:
		s += int(j)
	r = n * x - s
	if r >= 0:
		print(r)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	d = n * x - sum(l)
	if d > 0:
		print(d)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	x = b * a - sum(l)
	if x < 0:
		print(0)
	else:
		print(x)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	bulb = list(map(int, input().split()))
	tot = sum(bulb)
	req = n * x - tot
	if req >= 0:
		print(req)
	else:
		print(0)


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	c = list(map(int, input().split()))
	d = 0
	v = (sum(c) + d) / n
	while v < x:
		d = d + 1
		v = (sum(c) + d) / n
	print(d)
	t = t - 1


t = int(input())
i = 1
while i <= t:
	(n, x) = map(int, input().split())
	i = i + 1
	l = list(map(int, input().split()))
	s = sum(l)
	l1 = n * x - s
	if l1 > 0:
		print(l1)
	else:
		print('0')


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	v = (sum(l) + c) / n
	while v < x:
		c += 1
		v = (sum(l) + c) / n
	print(c)


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	lst = [int(i) for i in input().strip().split()][0:N - 1]
	tot_life = N * X
	sum_lst = sum(lst)
	diff = tot_life - sum_lst
	if diff < 0:
		print(0)
	else:
		print(diff)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	print(max(n * x - sum(l), 0))


t = int(input())
while t > 0:
	t = t - 1
	(a, b) = map(int, input().split())
	s = 0
	r = list(input().split())
	for i in range(a - 1):
		s = s + int(r[i])
	if s >= a * b:
		print('0')
	else:
		print(a * b - s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	a = n * k - s
	if a > 0:
		print(a)
	else:
		print(0)


def code():
	cases = int(input())
	for _ in range(cases):
		(N, X) = map(int, input().split(' '))
		lifetimes = list(map(int, input().split(' ')))
		last_blub_lifetime = N * X - sum(lifetimes)
		if last_blub_lifetime < 0:
			print(0)
			continue
		if sum(lifetimes) == 0:
			print(N * X)
			continue
		print(last_blub_lifetime)
code()


for i in range(int(input())):
	(N, X) = map(int, input().split())
	A = list(map(int, input().split()))
	x = X * N - sum(A)
	if x < 0:
		print(0)
	else:
		print(x)


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	A = map(int, input().split())
	bulb = N * X - sum(A)
	print(bulb) if bulb > 0 else print(0)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	c = list(map(int, input().split()))
	d = n * x - sum(c)
	if d > 0:
		print(d)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	t = 0
	for i in range(len(a)):
		t = t + a[i]
	c = n * x - t
	if c > 0:
		print(c)
	else:
		print(0)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	a = n * x
	b = 0
	for i in lst:
		b += i
	if a - b >= 0:
		print(a - b)
	else:
		print('0')


for tc in range(int(input())):
	(num_of_bulbs, mean_lifetime) = map(int, input().split())
	bulb_life_list = list(map(int, input().split()))
	calc = mean_lifetime * num_of_bulbs - sum(bulb_life_list)
	if calc < 0:
		print(0)
	else:
		print(calc)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	z = list(map(int, input().split()))
	a = 0
	for j in range(len(z)):
		a += z[j]
	c = x * y - a
	if c > 0:
		print(c)
	else:
		print(0)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	e = list(map(int, input().split()))
	d = a * b - sum(e)
	if d > 0:
		print(d)
	else:
		print(0)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	list = [int(i) for i in input().split()]
	p = n * x - sum(list)
	if p < 0:
		print(0)
	else:
		print(p)


t = int(input())
for r in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	f = n * x - sum(a)
	if f > 0:
		print(f)
	else:
		print('0')


m = int(input())
while m != 0:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for i in a:
		s = s + i
	d = x * n - s
	if d >= x:
		print(d)
	else:
		print(0)
	m = m - 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	List = list(map(int, input().split()))
	A = x * n - sum(List)
	if A > 0:
		print(x * n - sum(List))
	else:
		print(0)


for i in range(int(input())):
	(test_bulbs, average) = map(int, input().split())
	lifetime = list(map(int, input().split()))
	print(test_bulbs * average - sum(lifetime) if test_bulbs * average - sum(lifetime) > 0 else 0)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	f = x * n - sum(arr)
	print(f if f > 0 else 0)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	s = input().split()
	a = 0
	for i in range(len(s)):
		a += int(s[i])
	ans = x * y - a
	if ans >= 0:
		print(ans)
	else:
		print(0)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	z = x * y
	if z <= s:
		print(0)
	else:
		print(z - s)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	bulb = list(map(int, input().split()))
	ans = x * n - sum(bulb)
	if ans >= 0:
		print(ans)
	else:
		print(0)


T = int(input())
for i in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	d = n * x - sum(a)
	if d > 0:
		print(d)
	else:
		print(0)