#C6195. Maximum Revenue Difference
Maximum Revenue Difference
Maximum Revenue Difference
You are given the revenue data of several months for each test case. For each test case, you need to determine the maximum revenue difference between any two months such that the revenue of the later month is strictly greater than the revenue of an earlier month.
More formally, given an array \(a = [a_1, a_2, \dots, a_m]\) where \(m\) is the number of months, you need to find the maximum value of \(a_j - a_i\) where \(1 \le i < j \le m\) and \(a_i < a_j\). If no such pair exists or if \(m < 2\), output \(-1\).
Example: For the revenue data [7, 1, 5, 3, 6], the maximum revenue difference is \(6 - 1 = 5\). For [9, 4, 3, 2] there is no valid pair so the answer is \(-1\).
inputFormat
The first line of the input contains a single integer \(T\) which denotes the number of test cases. Each test case is described as follows:
- The first line contains an integer \(m\) denoting the number of months.
- The second line contains \(m\) space-separated integers, where the \(i\)-th integer represents the revenue in the \(i\)-th month.
It is guaranteed that \(1 \le T \le 10\) and \(1 \le m \le 10^5\). The revenues are integers that may be positive, zero, or negative.
outputFormat
For each test case, output a single line containing one integer, the maximum revenue difference calculated as described. If no valid pair exists, output \(-1\).
## sample2
5
7 1 5 3 6
4
9 4 3 2
5
-1
</p>