#K39302. Minimizing Array Sum Difference

    ID: 26390 Type: Default 1000ms 256MiB

Minimizing Array Sum Difference

Minimizing Array Sum Difference

Problem Statement:

You are given an array of n integers and a target integer k. In one operation, you can increment or decrement any element by 1. Your goal is to make the sum of all array elements equal to k. The minimum number of operations required is given by the formula:

$$|\sum_{i=1}^{n}a_i - k|$$

where \(|\cdot|\) represents the absolute value.

Note: Each increment or decrement counts as one operation.

inputFormat

Input Format:

  • The first line contains an integer t denoting the number of test cases.
  • For each test case, the first line contains two space-separated integers n and k.
  • The second line contains n space-separated integers representing the array elements.

outputFormat

Output Format:

For each test case, output a single integer representing the minimum number of operations required to make the sum of the array equal to k. Each answer should be printed on a new line.

## sample
4
3 6
1 2 3
4 10
1 1 1 1
2 200
50 150
2 100
20 30
0

6 0 50

</p>