#C8552. Maximum Profit
Maximum Profit
Maximum Profit
You are given a sequence of stock prices for consecutive days. Each price represents the price of a single share on that day. Your task is to determine the maximum profit achievable by executing exactly one transaction (i.e., buying one share and then later selling it). If no profit is possible, return 0.
More formally, if the prices for n days are given as an array \(P = [p_1, p_2, \ldots, p_n]\), you need to find the maximum value of \(p_j - p_i\) for \(1 \leq i < j \leq n\). If no such pair \((i, j)\) exists which results in a profit (i.e. \(p_j \leq p_i\) for all \(i, j\)), then the answer is 0.
Input Format:
The input is given through standard input (stdin). The first line contains an integer \(n\), which denotes the number of days. The second line contains \(n\) space-separated integers representing the prices.
Output Format:
Output the maximum profit achievable on a single line to standard output (stdout).
inputFormat
The first line of input contains an integer \(n\) denoting the number of days. The second line contains \(n\) space-separated integers representing the stock prices.
outputFormat
Output a single integer which is the maximum profit achievable. If no profit can be made, output 0.
## sample6
7 1 5 3 6 4
5