#C14982. Maximum Stock Profit
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
and if this value is negative, output 0.
inputFormat
The input is provided via stdin in the following format:
- An integer n representing the number of days.
- 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.
## sample6
7 1 5 3 6 4
5