#K42487. Maximum Difference and Minimum Sum Pair
Maximum Difference and Minimum Sum Pair
Maximum Difference and Minimum Sum Pair
You are given a list of integers representing the power values of trees. For each test case, your task is to compute two values:
- Maximum Difference (D): The difference between the largest and smallest integer in the list.
- Minimum Sum (S): The sum of the two smallest integers in the list.
This method is based on the observation that if the list is sorted in non-decreasing order, then:
- D = a[n-1] - a[0] where a[0] is the smallest element and a[n-1] is the largest.
- S = a[0] + a[1], since these are the two smallest values (ensuring the smallest possible sum among any pair). </p>
- The first line contains an integer
N
— the number of trees. - The second line contains
N
space-separated integers that represent the power values of the trees. - The first integer is the maximum difference, \(D = a_{n-1} - a_0\).
- The second integer is the sum of the two smallest integers, \(S = a_0 + a_1\).
Note: It is guaranteed that each test case contains at least two integers.
inputFormat
The input begins with an integer T
representing the number of test cases. Each test case consists of two lines:
outputFormat
For each test case, output a single line with two space-separated integers:
2
3
1 5 9
4
-1 7 3 9
8 6
10 2
</p>