Minimal Product
Time limit2sMemory limit512 MB
Generate a pseudorandom array and find indices i<j with a_i<a_j minimizing the product a_i*a_j, or report IMPOSSIBLE.
- Level
Medium6 of 10
- Topics
- Implementation, Greedy, Math, Array
- Solved
- No attempts yet
Problem
You are given an array of integers . Find two indices and such that , , and the product is as small as possible.
Input
The input consists of several tests. The first line contains a single integer , the number of tests (). Each of the following lines describes one test.
Each test is generated using the following algorithm. The test is described by integers , , , , , , , (, , ), where is the length of the array.
First, the sequence of length is generated. The elements and are given. For , let . For each between and , (thus, ).
Use 64-bit integers to generate the sequence and avoid integer overflow.
The sum of over all tests does not exceed .
Output
For each test, print the smallest possible product on a separate line. If there are no indices and such that and , print "IMPOSSIBLE".
Hint
Consider how the array is generated in the first test.
First, the sequence is generated.
Then it is used to generate .
Thus, . The answer is .
In the second test the array is .