Problems
Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock
You are given an array of prices, where $prices_i$ contains the price of a stock on the $i$-th day.
You want to maximize your profit by selecting one day to buy one stock and choosing another day in the future to sell that stock.
Find the maximum profit that can be obtained from this transaction.
\InputFile
The first line contains the size $n~(n \le 10^5)$ of the price array. The second line contains the array of prices --- $n$ integers, each not exceeding $10^4$.
\OutputFile
Print the maximum profit that can be obtained from one transaction. If it is impossible to obtain profit, print $0$.
Input example #1
8 6 3 6 4 2 4 8 3
Output example #1
6
Input example #2
4 5 5 3 2
Output example #2
0