#C9557. Stock Trading Profit Maximization

    ID: 53663 Type: Default 1000ms 256MiB

Stock Trading Profit Maximization

Stock Trading Profit Maximization

You are given a sequence of n integers where each integer represents the price of a stock on that day. You are allowed to perform exactly one transaction: buy the stock on one day and sell it on a later day. Your task is to compute the maximum profit obtainable from this single transaction.

If no profit can be achieved (i.e. the stock price never increases), output 0.

The problem can be mathematically expressed as finding the maximum value of \(price_j - price_i\) for \(0 \le i < j < n\). If there is no such pair, the answer is 0.

Example:

Input: 6
       7 1 5 3 6 4
Output: 5

inputFormat

The first line contains a single integer n (which may be 0), representing the number of days. The second line contains n space-separated integers where each integer denotes the stock price on that day.

outputFormat

Print a single integer representing the maximum profit obtainable from one transaction. If no profit is possible, print 0.

## sample
6
7 1 5 3 6 4
5