#K71227. Maximum Difference in Score Order
Maximum Difference in Score Order
Maximum Difference in Score Order
You are given an integer n and a list of n integer scores representing the scores of participants in the order they appeared. Your task is to determine the maximum positive difference between the scores of any two participants such that the higher score comes from a participant who appeared after the one with the lower score.
Mathematically, given an array \(a_0, a_1, \dots, a_{n-1}\), find the maximum value of \(a_j - a_i\) for all \(0 \le i < j a_i\). If no such pair exists, return -1.
Note: If there is only one participant or none, the result is -1.
inputFormat
The input is given via standard input (stdin) and consists of:
- The first line contains an integer n — the number of participants.
- If n > 0, the second line contains n integers representing the scores of the participants, separated by spaces.
outputFormat
Output via standard output (stdout) a single integer denoting the maximum difference as described. If no valid pair exists, output -1.
## sample6
1 2 90 10 110 80
109
</p>