#C3494. Maximum Difference in Array
Maximum Difference in Array
Maximum Difference in Array
You are given an array of integers. Your task is to compute the maximum difference (\Delta = a_j - a_i) such that the element (a_j) (the larger element) comes after (a_i) (the smaller element) in the array. In other words, for indices (i < j), compute the maximum value of (a_j - a_i). If no such pair exists (i.e. the array is non-increasing or contains only one element), output (-1).
inputFormat
Input is read from standard input (stdin). The first line contains an integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single integer on standard output (stdout) which represents the maximum difference (a_j - a_i) (with (j > i)). If no valid pair exists, output (-1).## sample
7
2 3 10 6 4 8 1
8