SUMIJ
Problem
You are given an array consisting of N integers: . We need to find two positions and in the array , such that . If there are multiple pairs and that satisfy the above condition, we want the pair with the greatest difference . If there are multiple pairs with the same maximum difference, we want the one with the smallest value of .
Input Files:
The first line of the input will contain a positive integer , the number of queries. In each of the next queries, the first line will contain a natural number , the number of elements in the array. The second line will contain exactly integers , separated in pairs by a single space.
Output Files:
The output should contain lines. Each line should contain two numbers separated by a single space, indicating the requested positions and for the corresponding query. If no pair satisfies the conditions of the problem statement, the line should contain the word "IMPOSSIBLE".
Constraints
- , and the sum of over all queries will not exceed
- for each
Example of Input - Output Files:
STDIN (oddsum.in)
3
10
5 2 8 3 3 5 1 8 5 7
11
1 7 7 1 -4 8 9 7 9 4 5
6
1 2 -2 5 2 4
STDOUT (oddsum.out)
6 8
IMPOSSIBLE
2 5
Explanation of the Example
In the first query, the only segment of the array that has the desired property is the one between positions and , which has a sum of . In the second query, no segment of the array has the desired property. Finally, in the third query, there are three segments of the array that have the desired property:
- for and , it is ,
- for and , it is ,
- for and , it is .
Among the three, the first one has , while the other two have . Among the two with the maximum value of , the desired answer is the one with the smallest value of , which is , .
Notes
- For test cases worth 30%, of the total points, it will be \(Ν \le 1000\).
- For test cases worth 60%, of the total points, it will be \(Ν \le 10.000\).
Maximum execution time: 1 sec.
Maximum available memory: 64 MB.
Comments