#C3278. Maximum Stock Profit

    ID: 46687 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given a list of stock prices where the i-th element represents the price of a given stock on day i. Your task is to determine the maximum profit you can achieve by performing exactly one buy-sell transaction (i.e., buy one day and sell on a later day). If no profit can be made, output 0.

The maximum profit is computed as

\( \max_{0 \le i < j < n} (prices[j] - prices[i]) \)

If the prices are in a constant or decreasing trend, return 0.

inputFormat

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

  1. The first line contains a single integer n, the number of days (prices).
  2. The second line contains n space-separated integers representing the stock prices.

outputFormat

Output a single integer representing the maximum profit obtainable. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5