#C3380. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given a sequence of stock prices over ( n ) days. Your task is to calculate the maximum profit that can be achieved by buying on one day and selling on a later day. In other words, if the stock price on day ( i ) is ( p_i ), you need to find the maximum value of ( p_j - p_i ) where ( j > i ). If no profit can be achieved, the answer should be 0.
inputFormat
The input is provided via standard input (stdin). The first line contains a single integer ( n ) indicating the number of days. The second line contains ( n ) space-separated integers representing the stock prices on each day.
outputFormat
Output a single integer via standard output (stdout) representing the maximum profit achievable.## sample
6
7 1 5 3 6 4
5