#C1015. Maximum Product of Three Distinct Integers
Maximum Product of Three Distinct Integers
Maximum Product of Three Distinct Integers
Given an array of integers of size \(n\), your task is to find the maximum product obtainable by multiplying three distinct integers from the array. Two integers are considered distinct if their values differ. If the array does not contain at least three distinct integers, output IMPOSSIBLE
.
You can achieve the answer by considering two cases after sorting the array:
\( \max(a_{n-1} \times a_{n-2} \times a_{n-3},\; a_{n-1} \times a_{0} \times a_{1}) \)
where \(a_{n-1},a_{n-2},a_{n-3}\) are the three largest numbers and \(a_{0},a_{1}\) are the two smallest numbers.
inputFormat
The first number in the input is an integer \(n\) representing the number of elements. This is followed by \(n\) space-separated integers.
outputFormat
Output a single line containing the maximum product of three distinct integers. If it is not possible to choose three distinct integers, output IMPOSSIBLE
.
4 1 2 3 4
24