#C8475. Maximum Product of Two Numbers
Maximum Product of Two Numbers
Maximum Product of Two Numbers
Given an array of integers where the first integer represents the number of elements in the array, find the maximum product of any two distinct integers. The array may contain negative numbers, so note that the product of two negatives can yield a positive result.
The problem can be mathematically formulated as: $$\max_{1 \leq i < j \leq n} \; (a_i \cdot a_j)$$, where $$a_1, a_2, \ldots, a_n$$ are the array elements.
inputFormat
The input consists of multiple test cases. Each test case is given in one or more lines. For each test case, a line contains space‐separated integers where the first integer denotes the number of elements in the array and the following integers are the array elements. Input terminates when a line with a leading 0 is encountered.
outputFormat
For each test case, output the maximum product obtained by multiplying any two distinct numbers from the given array. Each result should be printed on its own line.## sample
5 10 20 30 40 50
0
2000
</p>