#K40562. Minimum Effort Running Path

    ID: 26670 Type: Default 1000ms 256MiB

Minimum Effort Running Path

Minimum Effort Running Path

Maria is training by running along various paths. Each path is represented by a sequence of elevations. Maria has to run from the beginning of the path to its end. However, at each step from elevation ai-1 to ai, she expends energy only if the elevation increases. The total effort required is the sum of all the positive differences between consecutive elevations.

Mathematically, if the elevations are given by an array a with n elements, the minimum effort E is computed as:

$$E = \sum_{i=1}^{n-1} \max(0, a_i - a_{i-1})$$

Your task is to calculate this minimum effort for each test case.

inputFormat

The input begins with an integer T denoting the number of test cases. For each test case, the first line contains an integer N which represents the number of positions in the path. The second line contains N space-separated integers representing the elevation at each position.

outputFormat

For each test case, output a single line containing the minimum effort required to traverse the path.## sample

3
5
1 2 3 2 4
4
4 2 3 5
3
10 5 2
4

3 0

</p>