#K81067. Maximum Product and Indices

    ID: 35671 Type: Default 1000ms 256MiB

Maximum Product and Indices

Maximum Product and Indices

Given an array of integers, your task is to compute the maximum product obtainable by multiplying any two distinct elements, and output the product along with the corresponding indices (in ascending order).

Note:

  1. If the array contains fewer than two elements, output -1 -1 -1.
  2. Both the product of two largest positive numbers and the product of two smallest (most negative) numbers can yield the maximum product.

Formally, let (n) be the number of elements and let the array be (a_0, a_1, \dots, a_{n-1}). You must find indices (i) and (j) (with (i < j)) such that the product (P = a_i \times a_j) is maximized. The result should be printed as: [ P,, i,, j ] with each value separated by a space.

inputFormat

The input is given via standard input (stdin). The first line contains a single integer (n) representing the number of elements in the array. The second line contains (n) space-separated integers representing the array elements.

outputFormat

Output via standard output (stdout) three integers separated by a space. They represent the maximum product and the two indices (in ascending order) used to form this product. If the array has fewer than two elements, output -1 -1 -1.## sample

5
3 5 -2 8 11
88 3 4