#C14600. Maximum Stock Profit

    ID: 44268 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given an array of stock prices for consecutive days. Your task is to determine the maximum profit that can be achieved by performing a single buy and a single sell transaction. In other words, find indices \( i \) and \( j \) such that \( j > i \) and the profit \( prices[j] - prices[i] \) is maximized. If no profit can be made, output 0.

The computation of profit can be represented by the formula:

[ profit = prices[j] - prices[i],\quad \text{for } j > i ]

If the prices are in decreasing order, then the maximum profit is 0.

inputFormat

The first line contains an integer \( n \) representing the number of days.

The second line contains \( n \) space-separated integers, where each integer denotes the stock price on that day.

\( 1 \leq n \leq 10^5 \) and each stock price is a non-negative integer.

outputFormat

Output a single integer representing the maximum profit that can be achieved from one buy-sell transaction. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5