#C5304. Largest Possible Difference
Largest Possible Difference
Largest Possible Difference
You are given an array of integers. Your task is to compute the largest possible difference between two elements such that the larger element appears after the smaller element in the array.
Formally, given an array \( a_1, a_2, \dots, a_n \), find the maximum value of \( a_j - a_i \) where \( 1 \le i a_i \). If no such pair exists, the answer is 0.
Input will be provided via standard input and your output should be printed to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers, which are the elements of the array.
outputFormat
Output a single integer on a new line denoting the maximum possible difference as defined above. If there is no valid pair, output 0.
## sample4
2 3 1 7
6
</p>