#C10273. Maximum Difference in Array

    ID: 39460 Type: Default 1000ms 256MiB

Maximum Difference in Array

Maximum Difference in Array

You are given an array of integers. Your task is to compute the maximum difference \(d = a_j - a_i\) where \(a_i\) and \(a_j\) are elements of the array and the index \(j\) comes after \(i\) (i.e. \(j > i\)). If no such pair exists that yields a positive difference, return 0.

Note: The formula for the difference is given by \(d = a_j - a_i\) for some \(j > i\), and you are required to maximize \(d\).

inputFormat

The input is given from standard input (stdin) in the following format:

n
a1 a2 a3 ... an

Here, n is the number of elements in the array, and each ai is an integer.

outputFormat

Output a single integer to standard output (stdout): the maximum difference \(d\) as described above. If no valid pair exists that yields a positive difference, output 0.

## sample
6
2 3 10 6 4 8
8