#C767. Maximum Profit Calculation

    ID: 51566 Type: Default 1000ms 256MiB

Maximum Profit Calculation

Maximum Profit Calculation

You are given the daily stock prices of a company for n days. Your task is to find the maximum profit achievable by performing at most one buy and one sell operation. You must buy the stock before you sell it.

The profit is computed as:

\(\text{profit} = \text{sell price} - \text{buy price}\)

If no profit is possible, return 0.

inputFormat

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

  • The first line contains a single integer n — the number of days.
  • The second line contains n space-separated integers representing the stock prices on each day.

If n is zero, there will be no prices provided.

outputFormat

Output to standard output (stdout) a single integer, which is the maximum profit that can be achieved. If no profit is possible, output 0.

## sample
6
7 1 5 3 6 4
5