#C11796. Maximum Profit from Stock Prices

    ID: 41151 Type: Default 1000ms 256MiB

Maximum Profit from Stock Prices

Maximum Profit from Stock Prices

You are given a list of stock prices where the i-th element represents the price of a stock on day i. Your task is to determine the maximum profit achievable by performing a single buy-sell transaction. If no profit can be achieved, output 0.

The profit is defined mathematically as follows:

\( \text{max\_profit} = \max_{0 \leq i < j < n}\{prices[j] - prices[i]\} \)

If there is no way to achieve a profit, the result should be 0.

inputFormat

The input is read from standard input and consists of two lines:

  • The first line contains a single integer n representing the number of days (0 ≤ n ≤ 105).
  • The second line contains n space-separated integers representing the stock prices.

If n is 0, the second line may be omitted.

outputFormat

Print a single integer to standard output denoting the maximum profit possible from one transaction.

## sample
6
7 1 5 3 6 4
5