0% found this document useful (0 votes)
6 views

B. Product of Array Elements

Uploaded by

bhd150208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

B. Product of Array Elements

Uploaded by

bhd150208
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The ICPC 2021 - Vietnam Central Provincial Contest

University of Science and Technology - The University of Danang

Problem B: Product of Array Elements


Time limit: 1s; Memory limit: 512 MB

Given array A consisting of n integers ai. Tuan wants to remove at most 1 element
in array A so that the product of all remaining elements in that array is the largest.
Please help Tuan do it!

You task is to calculate the product of all remaining elements in that array after
removed at most 1 element.

Input
- The first line contains a positive integer n (2 ≤ n ≤ 1000).
- Next line contains n integers ai separated by a space ( -109 ≤ ai ≤ 109).

Output
- Print the result of the problem. Since it may be too big, print it after taking modulo
109+7.

Sample
Input Output
4 120
4 2 3 5
5 16
-1 -2 -4 1 2

Explanation Example 1:
- Without dropping any elements, the product of 4 elements is 4 × 2 × 3 × 5 =
120.

Explanation Example 2:
- Remove -1, the product of the remaining 4 elements is -2 × (-4) × 1 × 2 = 16

You might also like