#C12769. Maximum Difference in Array Sequence

    ID: 42232 Type: Default 1000ms 256MiB

Maximum Difference in Array Sequence

Maximum Difference in Array Sequence

Given an array of integers, your task is to find the maximum difference between any two elements such that the larger element appears after the smaller one in the array. More formally, you need to compute \(\max_{i < j} (A[j] - A[i])\) where \(A\) is the given array. If no such pair exists, output \(-1\).

Input is received from standard input and output is to be printed to standard output.

inputFormat

The first line contains a single integer \(n\) — the number of elements in the array. The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output a single integer representing the maximum difference achievable such that the larger number comes after the smaller one. If no such pair exists, output \(-1\).

## sample
7
2 3 10 6 4 8 1
8

</p>