#K9646. Maximum Profit Calculation
Maximum Profit Calculation
Maximum Profit Calculation
You are given a list of stock prices. Your task is to determine the maximum profit achievable by performing exactly one buy and one sell operation. The buying must occur before the selling.
The profit is calculated using the formula: \(\text{profit} = \text{sell price} - \text{buy price}\). If no profit can be obtained, return \(0\).
inputFormat
The input consists of two lines. The first line contains a single integer \(n\), which is the number of price entries. The second line contains \(n\) space-separated integers representing the prices at different times.
outputFormat
Output a single integer representing the maximum profit obtainable by buying and then selling the stock. If no profit is available, output \(0\).
## sample6
7 1 5 3 6 4
5