#C5392. Maximum Height Difference
Maximum Height Difference
Maximum Height Difference
You are given the heights of n students standing in a line. The heights are provided in the order in which the students are lined up. Your task is to find the maximum difference in height between any two students such that the taller student appears after the shorter student in the line. Formally, if the heights are given by \(a_1, a_2, \dots, a_n\), you need to compute \(\max_{1 \leq i < j \leq n} (a_j - a_i)\). If no such pair exists (for example, if the list is non-increasing or contains fewer than two students), output 0.
Input Format: The first line contains an integer \(n\) representing the number of students. The second line contains \(n\) space-separated integers representing the student heights.
Output Format: Output a single integer denoting the maximum height difference.
inputFormat
The input is read from standard input.
- The first line contains a single integer \(n\) (the number of students).
- The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) where each \(a_i\) represents the height of the \(i\)-th student.
outputFormat
Print a single integer which is the maximum height difference such that the taller student comes after the shorter one.
## sample5
1 2 10 4 5
9