#K92867. Maximum Profit from Video Game Prices
Maximum Profit from Video Game Prices
Maximum Profit from Video Game Prices
You are given a sequence of daily video game prices. Your task is to determine the maximum profit that can be achieved over a single transaction, i.e. by buying on one day and selling on a later day. If no profit can be made, the result should be 0.
The profit is calculated using the formula:
$$\text{Profit} = P_{\text{sell}} - P_{\text{buy}}$$
where \(P_{\text{buy}}\) is the price on the buying day and \(P_{\text{sell}}\) is the price on the selling day, with the condition that the buying day comes before the selling day.
inputFormat
The input is provided via standard input (stdin) in the following format:
- The first line contains a single integer \(n\) representing the number of days.
- The second line contains \(n\) space-separated integers, where each integer represents the video game price on that day.
outputFormat
Output a single integer which is the maximum profit possible. If no profit can be made, output 0.
## sample6
7 1 5 3 6 4
5