P15581 [CodeChef] MAKEMONEY
普及-
题目描述

Chef has N bags and an integer X. The i^{th} bag contains A_{i} coins such that A_{i} ≤ X.

In one operation, Chef can:
Pick any bag and increase its coins to X. Formally, if he choses the i^{th} bag, he can set A_{i} = X.

Given that the cost of performing each operation is C (C ≤ X) coins and Chef can perform the above operation any (possibly zero) number of times, determine the maximum value of:
$\sum_{i=1}^N A_{i} -$ total cost paid by Chef, if Chef performs the operations optimally.

------ 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 three space-separated integers N, X, and C — the number of bags, maximum limit of coins on each bag and cost of each operation respectively.
  • The next line contains $N space-separated integers A_{1}, A_{2}, \dots, A_{N} -$ denoting the number of coins in each bag.

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

For each test case, output the maximum value of $\sum_{i=1}^N A_{i} -$ total cost paid by Chef.

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

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

----- Sample Input 1 ------
3
5 5 2
1 2 3 4 5
3 4 4
1 1 1
5 3 2
3 2 3 1 1

----- Sample Output 1 ------
18
3
10

----- explanation 1 ------
Test case $1$: It is optimal for Chef to perform $2$ operations:
- Operation $1$: Choose $i = 1$ and set $A_{1} = 5$ by using $2$ coins.
- Operation $2$: Choose $i = 2$ and set $A_{2} = 5$ by using $2$ coins.

The final array is $A = [5, 5, 3, 4, 5]$ and the total cost is $2+2 = 4$. Thus, the value of $\sum_{i=1}^N A_{i}$ $-$ total cost is $(5+5+3+4+5) - 4 = 22-4 = 18$.

Test case $2$: It is optimal for Chef to perform $0$ operations. Thus, the final array remains $[1, 1, 1]$ and the cost is $0$. The value of $\sum_{i=1}^N A_{i}$ $-$ total cost is $(1+1+1) - 0 = 3$.

Test case $3$: It is optimal for Chef to perform $0$ operations. Thus, the final array remains $[3, 2, 3, 1, 1]$ and the cost is $0$. The value of $\sum_{i=1}^N A_{i}$ $-$ total cost is $(3+2+3+1+1) - 0 = 10$.

输入格式

见题面

输出格式

见题面

样例输入
3 5 5 2 1 2 3 4 5 3 4 4 1 1 1 5 3 2 3 2 3 1 1
样例输出
18 3 10