#C8673. Maximum Segment Difference

    ID: 52681 Type: Default 1000ms 256MiB

Maximum Segment Difference

Maximum Segment Difference

You are given t test cases. Each test case consists of an integer n followed by n integers representing scores in non-decreasing order. Your task is to compute the difference between the maximum score and the minimum score of each test case.

Formally, if a test case consists of a sequence \(a_1, a_2, \dots, a_n\) (where \(a_1 \le a_2 \le \dots \le a_n\)), then the answer for that test case is computed as:

[ \text{Difference} = a_n - a_1 ]

Example:

Input:
3
6 1 3 4 5 6 7
4 2 2 2 2
5 1 5 9 13 16

Output: 6 0 15

</p>

In the first test case, the difference is \(7 - 1 = 6\); in the second test case it is \(2 - 2 = 0\); and in the third case, it is \(16 - 1 = 15\).

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains a single integer \(t\) representing the number of test cases.
  2. Each test case is described in one line starting with an integer \(n\), followed by \(n\) space-separated integers denoting the scores (sorted in non-decreasing order).

Example:

3
6 1 3 4 5 6 7
4 2 2 2 2
5 1 5 9 13 16

outputFormat

For each test case, output a single integer on a new line which is the maximum segment difference (i.e. \(a_n - a_1\)). The output is written to stdout.

For the sample input provided, the output should be:

6
0
15
## sample
3
6 1 3 4 5 6 7
4 2 2 2 2
5 1 5 9 13 16
6

0 15

</p>