#C2970. Maximum Pillar Height Difference
Maximum Pillar Height Difference
Maximum Pillar Height Difference
Given a list of pillar heights, determine the maximum difference in height between any two pillars such that the shorter pillar comes before the taller pillar in the list. In other words, if the pillar heights are represented by an array \(a\) of length \(n\), compute:
[ \text{result} = \max_{0 \leq i < j < n} (a[j] - a[i]) ]
If no such pair exists (i.e. the pillars are in non-increasing order), output 0.
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains an integer \(n\) \((1 \leq n \leq 10^5)\) representing the number of pillars.
- The second line contains \(n\) space-separated integers representing the heights of the pillars.
outputFormat
Output a single integer: the maximum height difference such that the smaller height appears before the larger one. If no valid pair exists, output 0.
## sample6
4 2 7 3 6 8
6