#C14982. Maximum Stock Profit

    ID: 44691 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 stock price on day i. Your task is to compute the maximum profit that can be obtained by choosing a day to buy and a later day to sell. If no profit can be achieved, return 0.

More formally, given an array prices of length n, you need to find the value

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

and if this value is negative, output 0.

inputFormat

The input is provided via stdin in the following format:

  1. An integer n representing the number of days.
  2. A line containing n space-separated integers indicating the stock prices.

For example:

6
7 1 5 3 6 4

outputFormat

Output a single integer representing the maximum profit obtainable. If no profit is possible, output 0. The result should be printed to stdout.

## sample
6
7 1 5 3 6 4
5