#K14951. Maximum Product of Two Numbers
Maximum Product of Two Numbers
Maximum Product of Two Numbers
You are given a list of integers. Your task is to compute the maximum product of any two distinct numbers in this list. If the list contains fewer than two integers, print -1
.
Let the list be \(A = [a_1, a_2, \dots, a_n]\). You need to find two indices \(i\) and \(j\) (with \(i \neq j\)) such that the product \(a_i \times a_j\) is maximized. If \(n < 2\), the answer is \(-1\).
Input Format: The first line contains an integer \(n\) indicating the number of integers. The second line contains \(n\) space-separated integers representing the list.
Output Format: Output a single integer: the maximum product of any two numbers in the list, or \(-1\) if fewer than two integers are provided.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) (\(n \ge 0\)), the number of elements in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Output a single integer which is the maximum product of any two numbers from the list. If the list has fewer than two numbers, output \(-1\).
## sample7
1 3 5 2 8 0 -1
40
</p>