#C9207. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
You are given the number of days \(N\) and a list of stock prices for each day. Your task is to compute the maximum profit that can be achieved by buying and selling the stock exactly once. If no valid profit can be made, output 0.
More formally, given a list of prices \(p_1, p_2, \ldots, p_N\), you need to find the maximum value of \(p_j - p_i\) such that \(1 \leq i < j \leq N\). If no positive profit is possible, return 0.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains an integer \(N\), the number of days.
- The second line contains \(N\) space-separated integers representing the stock prices for each day.
outputFormat
Output to standard output (stdout) a single integer representing the maximum profit that can be achieved by buying and selling the stock exactly once. If no profit can be achieved, output 0.
## sample6
7 1 5 3 6 4
5
</p>