#C1085. Maximum Stock Profit

    ID: 40100 Type: Default 1000ms 256MiB

Maximum Stock Profit

Maximum Stock Profit

You are given the stock prices for (N) days. Your task is to determine the maximum profit that can be obtained by buying the stock on one day and selling it on a future day. If no profit can be made, output 0.

The profit is calculated as follows: [ \text{Profit} = \text{price}{\text{sell}} - \text{price}{\text{buy}} ]

where (\text{price}{\text{buy}}) is the price on the day you buy the stock and (\text{price}{\text{sell}}) is the price on the day you sell it (and (\text{sell} > \text{buy})).

inputFormat

The first line contains a single integer (N) representing the number of days. The second line contains (N) space-separated integers representing the stock prices on each day. If (N = 0), then no prices are provided.

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