Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef has $N$ items in his shop (numbered $1$ through $N$); for each valid $i$, the price of the $i$-th item is $P_{i}$. Since Chef has very loyal customers, all $N$ items are guaranteed to be sold regardless of their price.

However, the government introduced a *price ceiling* $K$, which means that for each item $i$ such that $P_{i} > K$, its price should be reduced from $P_{i}$ to $K$.

Chef's *revenue* is the sum of prices of all the items he sells. Find the amount of revenue which Chef loses because of this price ceiling.

------  Input ------
The first line of the input contains a single 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$.
The second line contains $N$ space-separated integers $P_{1}, P_{2}, \ldots, P_{N}$.

------  Output ------
For each test case, print a single line containing one integer ― the amount of lost revenue.

------  Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10,000$
$1 ≤ P_{i} ≤ 1,000$ for each valid $i$
$1 ≤ K ≤ 1,000$

------  Subtasks ------
Subtask #1 (100 points): original constraints

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

5 4

10 2 3 4 5

7 15

1 2 3 4 5 6 7

5 5

10 9 8 7 6
----- Sample Output 1 ------ 
7

0

15
----- explanation 1 ------ 
Test Case 1: The initial revenue is $10 + 2 + 3 + 4 + 5 = 24$. Because of the price ceiling, $P_{1}$ decreases from $10$ to $4$ and $P_{5}$ decreases from $5$ to $4$. The revenue afterwards is $4 + 2 + 3 + 4 + 4 = 17$ and the lost revenue is $24 - 17 = 7$.

Test Case 2: The initial revenue is $1 + 2 + 3 + 4 + 5 + 6 + 7 = 28$. For each valid $i$, $P_{i} ≤ 15$, so there are no changes, the revenue after introduction of the price ceiling is the same and there is zero lost revenue.

Test Case 3: The initial revenue is $10 + 9 + 8 + 7 + 6 = 40$. Since $P_{i} > 5$ for each valid $i$, the prices of all items decrease to $5$. The revenue afterwards is $5 \cdot 5 = 25$ and the lost revenue is $40 - 25 = 15$.

Source: codechef | Difficulty: EASY
Tags: Implementation


Solutions:
for i in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))[:n]
	l = []
	for i in p:
		if i > k:
			l.append(k)
		else:
			l.append(i)
	print(sum(p) - sum(l))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	l = []
	for i in p:
		sum1 = sum1 + i
	for i in p:
		if i > k:
			l.append(k)
		else:
			l.append(i)
	for j in l:
		sum2 = sum2 + j
	print(sum1 - sum2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().strip().split()))
	summ = sum(lst)
	count = 0
	for i in range(n):
		if lst[i] <= k:
			count += lst[i]
		else:
			count += k
	print(abs(summ - count))


n = int(input())
for _ in range(n):
	(N, K) = list(map(int, input().split()))
	P = list(map(int, input().split()))
	loss = 0
	for price in range(len(P)):
		if P[price] > K:
			loss += P[price] - K
	print(loss)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = []
	for i in l1:
		if i > k:
			l2.append(k)
		else:
			l2.append(i)
	print(sum(l1) - sum(l2))


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	lst = [int(i) for i in input().split()][0:N]
	loss = 0
	for price in lst:
		if price > K:
			loss += price - K
	print(loss)


for i in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	i = 0
	total = 0
	while i < N:
		if A[i] > K:
			total = total + (A[i] - K)
		else:
			total = total
		i = i + 1
	print(total)


T = int(input())
for i in range(T):
	sum = 0
	count = 0
	(N, K) = map(int, input().split())
	P = list(map(int, input().split()))
	for j in P:
		sum = sum + j
		if j > K:
			count = count + K
		else:
			count = count + j
	print(sum - count)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	list = map(int, input().split())
	list2 = []
	for i in list:
		if i > K:
			c = i - K
			list2.append(c)
	print(sum(list2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	P = list(map(int, input().split()))
	s = sum(P)
	c = 0
	for i in range(len(P)):
		if P[i] > k:
			P[i] = k
	t = sum(P)
	print(s - t)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	P = list(map(int, input().split()))
	PriceAfterK = []
	initialRevenue = sum(P)
	for i in P:
		if i > K:
			PriceAfterK.append(K)
		else:
			PriceAfterK.append(i)
	revenueAfterK = sum(PriceAfterK)
	print(initialRevenue - revenueAfterK)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	price_lst = list(map(int, input().split()))
	loss = 0
	for price in price_lst:
		if price > k:
			loss += price - k
	print(loss)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = input().split()
	s1 = s2 = 0
	for j in a:
		if int(j) > k:
			s1 += int(j)
			s2 += k
		else:
			s1 += int(j)
			s2 += int(j)
	print(s1 - s2)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	sum1 = sum(m)
	filtering = list(filter(lambda x: x > b, m))
	sum2 = 0
	if len(filtering) == 0:
		print('0')
	else:
		for j in m:
			if j > b:
				sum2 = sum2 + b
			else:
				sum2 = sum2 + j
		print(sum1 - sum2)


for _ in range(int(input())):
	(x, b) = map(int, input().split())
	a = list(map(int, input().split()))
	l = sum(a)
	c = 0
	for i in a:
		if i > b:
			c += b
		else:
			c += i
	print(l - c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	a = sum(p)
	for i in range(n):
		if p[i] > k:
			p[i] = k
	b = sum(p)
	print(a - b)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst2 = []
	for i in range(a):
		if lst[i] > b:
			lst2.append(b)
		else:
			lst2.append(lst[i])
	print(sum(lst) - sum(lst2))


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l1 = [int(x) for x in input().split()]
	r1 = sum(l1)
	r2 = 0
	for val in l1:
		if val > b:
			r2 = r2 + b
		else:
			r2 = r2 + val
	print(r1 - r2)


for case in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	x = sum(p)
	for i in range(n):
		if p[i] > k:
			p[i] = k
	print(x - sum(p))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for j in range(n):
		if a[j] > k:
			s = s + (a[j] - k)
	print(s)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	P = map(int, input().split())
	price_ceiling = 0
	for i in P:
		if i > K:
			price_ceiling += i - K
	print(price_ceiling)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = list(map(int, input().split()))
	ans = sum(x)
	for i in range(a):
		if x[i] > b:
			x[i] = b
	print(ans - sum(x))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	s = sum(p)
	q = []
	for i in range(n):
		if p[i] > k:
			q.append(k)
		else:
			q.append(p[i])
	s2 = sum(q)
	print(s - s2)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	p = list(map(int, input().split()))
	t1 = 0
	t2 = 0
	for j in range(n):
		t1 = t1 + p[j]
	for l in range(n):
		if p[l] > k:
			p[l] = k
		t2 = t2 + p[l]
	print(t1 - t2)


for z in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	s = 0
	t = 0
	for k in range(a):
		t = t + c[k]
	for v in c:
		if v > b:
			s += b
		else:
			s += v
	print(t - s)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	c = [int(a) for a in input().split()]
	total = sum(c)
	count = 0
	for i in c:
		if i >= b:
			count += b
		else:
			count += i
	print(total - count)


for i in range(int(input())):
	count = 0
	p = []
	(n, k) = map(int, input().split(' '))
	p.extend(map(int, input().split(' ')))
	for j in p:
		if j > k:
			count += j - k
	print(count)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	p = [int(x) for x in input().split()]
	l = []
	for i in p:
		if i > k:
			l.append(k)
		else:
			l.append(i)
	print(sum(p) - sum(l))


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


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	m = []
	sum = 0
	for i in l:
		if i > k:
			sum = sum + (i - k)
	print(sum)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	for i in a:
		if i > k:
			sum += i - k
	print(sum)


t = int(input())
for i in range(0, t):
	sum2 = 0
	(m, n) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	sum1 = sum(l)
	for i in l:
		if i > n:
			sum2 += n
		else:
			sum2 += i
	print(sum1 - sum2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().strip().split()))
	t = []
	for i in s:
		if i > k:
			t.append(k)
		else:
			t.append(i)
	g = sum(s)
	h = sum(t)
	print(g - h)


t = int(input())
for i in range(t):
	b = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	k = b[1]
	z = sum(a)
	for i in range(len(a)):
		if a[i] > k:
			a[i] = k
	if z - sum(a) >= 0:
		print(z - sum(a))
	else:
		print(0)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	sum1 = sum(p)
	for i in range(len(p)):
		if p[i] > k:
			p[i] = k
	sum2 = sum(p)
	print(sum1 - sum2)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = []
	l = list(map(int, input().split()))
	for j in l:
		if j > b:
			c.append(b)
		else:
			c.append(j)
	print(sum(l) - sum(c))


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	sum = 0
	for j in d:
		if j > c:
			sum += abs(j - c)
	print(sum)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	ans = 0
	for j in range(n):
		if p[j] > k:
			ans += p[j] - k
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = []
	for i in c:
		if i >= b:
			d.append(b)
		else:
			d.append(i)
	print(sum(c) - sum(d))


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	p = list(map(int, input().split()))
	total = sum(p)
	res = 0
	for i in range(n):
		if p[i] > k:
			p[i] = k
	s2 = sum(p)
	print(total - s2)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	p = list(map(int, input().split()))
	r = 0
	for i in p:
		if i > k:
			i = i - k
			r = r + i
	print(r)


for i in range(int(input())):
	(items, value) = map(int, input().split())
	lis = list(map(int, input().split()))
	initial = sum(lis)
	after = sum([min(i, value) for i in lis])
	print(initial - after)


from math import *
for t in range(int(input())):
	(num, k) = map(int, input().split())
	a = list(map(int, input().split()))[:num]
	s = 0
	for val in a:
		if val >= k:
			s += k
		else:
			s += val
	print(sum(a) - s)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	a = sum(p)
	l = list()
	for j in p:
		if k < j:
			j = k
			l.append(j)
		else:
			l.append(j)
	b = sum(l)
	c = a - b
	if c > 0:
		print(c)
	else:
		print('0')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = list(map(int, input().split()))
	a = 0
	for i in range(n):
		if d[i] > k:
			a += d[i] - k
	print(a)


t = int(input())
for i in range(t):
	(n, p) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))[:n]
	c = 0
	for i in range(n):
		if l[i] > p:
			c = c + (l[i] - p)
	print(c)


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


for i in range(int(input())):
	(x, y) = map(int, input().split())
	s = input().split()
	(k, o) = (0, 0)
	for i in s:
		k += int(i)
		if int(i) > y:
			o += y
		else:
			o += int(i)
	print(k - o)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split())
	P = list(map(int, input().split()))
	TotalValue = 0
	for i in range(N):
		if P[i] > K:
			TotalValue += K
		else:
			TotalValue += P[i]
	Total = sum(P)
	print(Total - TotalValue)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	su = 0
	a = sum(p)
	for i in range(n):
		if p[i] >= k:
			su += k
		else:
			su += p[i]
	print(a - su)


T = int(input())
for i in range(T):
	(a, b) = list(map(int, input().split()))
	c = list(map(int, input().split()))
	f = sum(c)
	for i in range(len(c)):
		if c[i] > b:
			c[i] = b
	u = sum(c)
	print(f - u)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(k - int(i)) for i in input().split() if int(i) > k]
	print(abs(sum(l)))


for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	s = sum(l)
	for j in range(len(l)):
		if l[j] > b:
			l[j] = b
	t = sum(l)
	print(s - t)


for i in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	s1 = sum(l)
	s2 = 0
	for i in l:
		if i > y:
			i = y
			s2 = s2 + i
		else:
			s2 = s2 + i
	print(s1 - s2)


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	total_cost = 0
	ceilling_cost = 0
	for i in range(n):
		total_cost = total_cost + p[i]
		if p[i] > k:
			ceilling_cost = ceilling_cost + k
		else:
			ceilling_cost = ceilling_cost + p[i]
	print(total_cost - ceilling_cost)


tc = int(input())
for _ in range(tc):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	f = sum(l)
	for i in range(0, a):
		if l[i] > b:
			l[i] = b
	s = sum(l)
	print(f - s)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	x = sum(l)
	for i in l:
		if i > b:
			l[l.index(i)] = b
	print(x - sum(l))


for i in range(int(input())):
	l1 = []
	(N, K) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in l:
		if i > K:
			l1.append(K)
		else:
			l1.append(i)
	print(sum(l) - sum(l1))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	p = list(map(int, input().split()))
	i = 0
	loss = 0
	for i in range(n):
		if p[i] > k:
			loss += p[i] - k
	print(loss)
	t -= 1