#C5395. Elevation Changes
Elevation Changes
Elevation Changes
You are given a set of hiking trip records. For each test case, you are given the daily changes in elevation. Your task is to compute the total elevation gain (i.e. the sum of all positive changes) and the total elevation loss (i.e. the sum of all negative changes) for each test case.
The calculations are defined as follows:
$$ \text{Total Gain} = \sum_{i=1}^{n} \max(0, \Delta h_i) $$
$$ \text{Total Loss} = \sum_{i=1}^{n} \min(0, \Delta h_i) $$
where \(\Delta h_i\) represents the change in elevation on the \(i^{th}\) day.
Output the results for each test case on a separate line, with the gain and loss separated by a space.
inputFormat
The input is provided via standard input (stdin).
The first line contains a single integer \(T\) denoting the number of test cases. For each test case:
- The first line contains an integer \(n\) representing the number of days.
- The second line contains \(n\) space-separated integers representing the daily elevation changes.
outputFormat
For each test case, output a single line on standard output (stdout) with two integers: the total elevation gain and the total elevation loss, separated by a space.
## sample2
7
100 -20 30 -10 -50 60 40
5
-10 20 -30 40 -50
230 -80
60 -90
</p>