#K4636. Maximum Upward Heart Rate Difference
Maximum Upward Heart Rate Difference
Maximum Upward Heart Rate Difference
You are given a number n
representing the number of heart rate recordings during a day, followed by n
integers which represent the heart rates in chronological order. Your task is to find the maximum upward difference between two recordings such that the latter recording happens after the former.
Formally, if the recorded heart rates are given as an array heart_rates
, you need to compute:
\( \max_{0 \leq i < j < n} \{ \; heart\_rates[j] - heart\_rates[i] \} \)
If no such upward difference exists (i.e. the heart rate never increases), output 0
.
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains a single integer
n
(the number of heart rate recordings). - The second line contains
n
space-separated integers representing the heart rate recordings in the order they were taken.
outputFormat
The output, printed to stdout, is a single integer representing the maximum upward heart rate difference. If no such difference exists, output 0
.
7
70 85 75 90 80 95 100
30