Best Product of Three
Choose three elements whose product is maximal and print that product. Values may be negative.
Input: the first line has N (N ≥ 3); the second line has N integers.
Output: the maximum product of any three elements.
Constraints:
- 3 ≤ N ≤ 105
- −104 ≤ ai ≤ 104
Sample Tests
Input 1
5 -10 -10 1 3 2
Output 1
300
Input 2
3 1 2 3
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.