3935: Maximum product
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:5
解决:3
题目描述
To enter a sequence S of n elements.
You need to find a contiguous subsequence with the largest product.
If the largest product is not a positive number, then output -1.
E.g.
1. The input is: 1 2 3 -4 5
The largest product is 1*2*3 = 6, and your output is 6.
2. The input is: 1 2 3 -4 -5
The largest product is 1*2*3*(-4)*(-5) = 120, and your output is 120.
You need to find a contiguous subsequence with the largest product.
If the largest product is not a positive number, then output -1.
E.g.
1. The input is: 1 2 3 -4 5
The largest product is 1*2*3 = 6, and your output is 6.
2. The input is: 1 2 3 -4 -5
The largest product is 1*2*3*(-4)*(-5) = 120, and your output is 120.
输入
The input includes multiple sets of data.
Each set of data first line is a positive integer n, and the second line is a sequence of n elements S
1<=n<=18,-10<=Si<=10
Each set of data first line is a positive integer n, and the second line is a sequence of n elements S
1<=n<=18,-10<=Si<=10
输出
Output the largest product and wrap.
样例输入 复制
3
2 4 -3
5
2 5 -1 2 -1
样例输出 复制
8
20