#C13003. Maximum Stock Profit
Maximum Stock Profit
Maximum Stock Profit
Given the stock prices over a period, determine the best day to buy and the best day to sell a stock to maximize profit. The profit is defined as:
\(\text{profit} = \text{price}_{\text{sell}} - \text{price}_{\text{buy}}\)
If no profit is possible, output None None
. Note that the days are indexed starting from 0.
inputFormat
The input consists of two lines. The first line contains an integer \(n\) representing the number of days. The second line contains \(n\) space-separated integers representing the stock prices for each day.
outputFormat
If a profitable transaction exists, print two integers separated by a space indicating the best day to buy and the best day to sell. Otherwise, print None None
.
6
7 1 5 3 6 4
1 4