#K49192. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
Given the stock prices of a company over n consecutive days, your task is to determine the maximum profit that can be achieved by buying one share on one day and selling it on a later day.
You are to compute \(max\,(p_j - p_i)\) for all \(i < j\). If no profit can be made (i.e. the price never increases after a purchase), output \(0\).
inputFormat
The input consists of two lines. The first line contains an integer \(n\) (\(n \ge 2\)), representing the number of days. The second line contains \(n\) space-separated integers, where each integer denotes the stock price on that day.
outputFormat
Output a single integer, which is the maximum profit that can be achieved by buying on one day and selling on a later day. If no profit is possible, output \(0\).
## sample6
7 1 5 3 6 4
5