#K14616. Maximum Profit from Stock Prices
Maximum Profit from Stock Prices
Maximum Profit from Stock Prices
You are given a list of integers representing the stock prices of a company over consecutive days. Your task is to compute the maximum profit that can be made by performing a single buy-sell transaction. In other words, you need to choose one day to buy and a later day to sell to maximize your profit. If no profit can be achieved, output 0.
The profit is calculated as: \(\text{profit} = \text{sell price} - \text{buy price}\).
inputFormat
The input is read from stdin. The first line contains an integer \(n\), which represents the number of days. The second line contains \(n\) space-separated integers that represent the stock prices. If \(n = 0\), there will be no second line.
outputFormat
Output a single integer to stdout — the maximum profit obtainable from one buy-sell transaction. If no profit is possible, output 0.
## sample6
7 1 5 3 6 4
5
</p>