#C11872. Maximum Stock Profit Days
Maximum Stock Profit Days
Maximum Stock Profit Days
Given the stock prices of a company over N days, your task is to determine the best day to buy and the best day to sell in order to achieve the maximum profit. Days are numbered from 1 to N. If no profit is possible, output 0 0
.
Note: You must read the input from standard input (stdin) and produce the output to standard output (stdout).
The problem can be mathematically represented as finding indices \( i \) and \( j \) (with \( 1 \le i 0 \), the answer should be 0 0
.
inputFormat
The input is given in the following format via standard input:
T N1 price1 price2 ... priceN1 N2 price1 price2 ... priceN2 ... NT price1 price2 ... priceNT
Where:
T
is the number of test cases.- For each test case, the first line contains an integer
N
denoting the number of days. - The second line contains
N
space-separated integers representing the stock prices.
outputFormat
For each test case, output a single line containing two integers separated by a space: the optimal buy day and the sell day (both 1-indexed) that yield the maximum profit. If no profitable transaction exists, output 0 0
.
2
6
7 1 5 3 6 4
5
7 6 4 3 1
2 5
0 0
</p>