#K64802. Minimum Operations to Zero

    ID: 32056 Type: Default 1000ms 256MiB

Minimum Operations to Zero

Minimum Operations to Zero

You are given an array of n integers. Your task is to determine the minimum number of operations required to transform every element of the array to zero. You are allowed to perform the following two types of operations:

  • Increment or decrement operation: Increase or decrease every element of the array by 1 simultaneously.
  • Swap operation: Swap any two elements in the array.

It turns out that an optimal strategy is to simply change each element individually toward zero. Therefore, the minimum number of operations is equal to the sum of the absolute values of each element. This can be mathematically expressed as: \[ \text{Operations} = \sum_{i=1}^{n} |a_i| \]

Note that the swap operation does not help to reduce the total number of required operations when using the optimal strategy.

inputFormat

The first line of input contains a single integer T (the number of test cases). Each test case is described as follows:

  1. The first line contains an integer n, the number of elements in the array.
  2. The second line contains n space-separated integers representing the array elements.

outputFormat

For each test case, output a single line containing the minimum number of operations required to turn all the elements of the array to zero.

## sample
5
3
3 2 1
4
-1 -2 -3 -4
5
0 0 0 0 0
3
5 -4 3
2
10 -10
6

10 0 12 20

</p>