Uphill and Downhill

We have the altitude data recorded by a watch during a walk. The clock
registers, at each unit of time, the height in meters above sea level.
Write a program such that, given the sequence of altitudes, calculates
the following three values:

- The cumulative positive slope. That is, the accumulated height gains
  on the walk.

- The cumulative negative slope. That is, the accumulated loss of height
  on the walk.

- The highest cumulative slope in an uphill section. An uphill section
  is characterized by not having any elevation loss.

For example, given the sequence of heights 1 2 2 4 3 5 4, the cumulative
positive slope is 5, the cumulative negative slope is 2, and the highest
cumulative slope in an uphill section is 3.

Exam score: 4 Automatic part: 40%

Input

On entry there is a non-negative integer n followed by a series of n
cases. Each case consists of a sequence of heights. Each height is a
nonnegative integer. Right after the sequence appears the -1 mark.

Output

For each case, a line with the cumulative positive slope, the cumulative
negative slope, and the highest cumulative slope in an uphill section.

Problem information

Author: Pro1

Generation: 2026-01-25T14:24:53.842Z

© Jutge.org, 2006–2026.
https://jutge.org
