#C7381. Maximum Stock Trading Profit
Maximum Stock Trading Profit
Maximum Stock Trading Profit
You are given a list of stock prices represented as integers, where each integer indicates the price of the stock on a specific day.
Your task is to compute the maximum profit that can be achieved by buying the stock on one day and selling it on a later day. If no profit is possible, output 0.
Mathematically, if the stock prices are given by \( p_1, p_2, \dots, p_n \), you need to find:
\( \max_{1 \leq i < j \leq n} (p_j - p_i) \)
If the computed maximum is negative, the result should be 0.
inputFormat
The first line contains an integer \( n \), representing the number of days.
The second line contains \( n \) space-separated integers where each integer represents the stock price on that day.
outputFormat
Output a single integer which is the maximum profit achievable. If no profit is possible, output 0.
## sample6
7 1 5 3 6 4
5