#C10618. Maximum Stock Profit

    ID: 39843 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given the stock prices of a company over n days. Your task is to compute the maximum profit that can be made by performing one buy-sell transaction. You must buy the stock on one day and sell it on a later day.

If no profit can be made, output 0.

The problem can be modeled as finding the maximum difference \(p_j - p_i\) for \(j > i\). Here, \(p_i\) represents the price on day \(i\).

inputFormat

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

  • The first line contains an integer n representing the number of days.
  • The second line contains n space-separated integers where each integer represents the stock price on that day.

For example:

6
7 1 5 3 6 4

outputFormat

Output a single integer to standard output (stdout) which represents the maximum profit achievable from a single buy-sell transaction. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5

</p>