#K58097. Max Sum and Difference Problem

    ID: 30566 Type: Default 1000ms 256MiB

Max Sum and Difference Problem

Max Sum and Difference Problem

You are given t test cases. For each test case, you are provided with an array of n integers. Your task is to compute two values for each test case:

  • The sum of all elements in the array, expressed as \(S = \sum_{i=1}^{n} a_i\).
  • The difference between the maximum and minimum elements in the array, expressed as \(D = \max(a) - \min(a)\).

Note that although the problem statement mentions reordering of the elements, both the sum and the difference remain invariant under any rearrangement.

For each test case, output the computed values \(S\) and \(D\) on a single line, separated by a space.

inputFormat

The first line of the input contains a single integer t denoting the number of test cases. Each test case consists of two lines:

  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, print a single line containing two space-separated integers: the sum of the array elements and the difference between the maximum and minimum element of the array.

## sample
1
3
-1 2 3
4 4

</p>