#K6981. Maximum Temperature Difference
Maximum Temperature Difference
Maximum Temperature Difference
You are given a sequence of daily temperatures. Your task is to compute the maximum difference \(T_j - T_i\) such that \(j > i\) and \(T_j > T_i\). In other words, find two days where the temperature increases and the difference is maximized. If no such pair exists, return 0.
The input is provided via standard input (stdin). The first line contains an integer \(n\) (which can be 0), representing the number of days. The second line (if \(n > 0\)) contains \(n\) space-separated integers in the range \([-100, 100]\) representing the daily temperatures.
Note: If the temperature never increases from any earlier day to a later day, the answer is 0.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\), the number of days.
- If \(n > 0\), the second line contains \(n\) space-separated integers representing the temperature for each day.
outputFormat
Output a single integer representing the maximum temperature difference \(T_j - T_i\) with \(j > i\) and \(T_j > T_i\). If no valid pair exists, output 0.
## sample5
30 40 20 50 25
30
</p>