题目描述
Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss.
Example
$price=[20,15,8,2,12]$
Her minimum loss is incurred by purchasing in year $2$ at $price[1]=15$ and reselling in year $5$ at $price[4]=12$. Return $15-12=3$.
Function Description
Complete the minimumLoss function in the editor below.
minimumLoss has the following parameter(s):
int price[n]: home prices at each year
Returns
int: the minimum loss possible
Input Format
The first line contains an integer $n$, the number of years of house data.
The second line contains $n$ space-separated long integers that describe each $\textit{price[i]}$.
Constraints
$2\leq n\leq2\times10^5$
$1\leq price[i]\leq10^{16}$
All the prices are distinct.
A valid answer exists.
Subtasks
$2\leq n\leq1000$ for $50\%$ of the maximum score.
Sample Input 0
3
5 10 3
Sample Output 0
2
Explanation 0
Lauren buys the house in year $1$ at $price[0]=5$ and sells it in year $3$ at $price[2]=3$ for a minimal loss of $5-3=2$.
Sample Input 1
5
20 7 8 2 5
Sample Output 1
2
Explanation 1
Lauren buys the house in year $2$ at $price[1]=7$ and sells it in year $5$ at $price[4]=5$ for a minimal loss of $7-5=2$.
输入格式
见题面
输出格式
见题面