#K80817. Best Days to Trade

    ID: 35615 Type: Default 1000ms 256MiB

Best Days to Trade

Best Days to Trade

Given a list of stock prices, your task is to determine the best day to buy and the best day to sell in order to maximize your profit. More formally, let (P = [p_0, p_1, \dots, p_{n-1}]) be the sequence of prices. You need to choose two indices (i) and (j) with (0 \le i < j < n) such that the profit (p_j - p_i) is maximized. If no positive profit exists, output (-1) for both days.

Input is provided from standard input and output must be written to standard output. The first number in the input represents the number of price entries, followed by the list of prices. For example, if the input is:
6\n7 1 5 3 6 4
then the output should be:
1 4 (indicating that buying on day 1 and selling on day 4 yields the maximum profit).

inputFormat

The input is read from standard input. The first line contains a single integer (n) (the number of stock prices). The second line contains (n) space-separated integers representing the stock prices.

outputFormat

Output two space-separated integers: the best day to buy and the best day to sell. If no valid transaction (i.e. profitable transaction) is possible, output "-1 -1".## sample

6
7 1 5 3 6 4
1 4