#C3778. Best Stock Trading Days
Best Stock Trading Days
Best Stock Trading Days
You are given the prices of a stock for n consecutive days. Your task is to determine the best day to buy and the best day to sell in order to achieve the maximum profit. If no profit can be made, output -1 -1
.
More formally, given a sequence of stock prices \(a_0, a_1, \dots, a_{n-1}\), you need to find two indices \(i\) and \(j\) (with \(i < j\)) such that the profit \(a_j - a_i\) is maximized. If the maximum profit is 0 or no such pair exists, you should output \(-1 -1\).
Note: The days are considered 0-indexed.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(n\) representing the number of days.
- If \(n > 0\), the second line contains \(n\) space-separated integers denoting the stock prices for each day.
outputFormat
Output to standard output (stdout) two space-separated integers. These integers represent the 0-indexed day on which to buy and the day on which to sell to achieve the maximum profit. If no profit is possible, output -1 -1
.
6
7 1 5 3 6 4
1 4
</p>