B. Good Kid

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Slavic is preparing a present for a friend's birthday. He has an array a� of n� digits and the present will be the product of all these digits. Because Slavic is a good kid who wants to make the biggest product possible, he wants to add 11 to exactly one of his digits.

What is the maximum product Slavic can make?

Input

The first line contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases.

The first line of each test case contains a single integer n� (1≤n≤91≤�≤9) — the number of digits.

The second line of each test case contains n� space-separated integers ai�� (0≤ai≤90≤��≤9) — the digits in the array.

Output

For each test case, output a single integer — the maximum product Slavic can make, by adding 11 to exactly one of his digits.

Example

input

Copy

 

4

4

2 2 1 2

3

0 1 2

5

4 3 2 3 4

9

9 9 9 9 9 9 9 9 9

output

Copy

16
2
432
430467210

解题说明:此题是一道数学题,为了让乘积最大,很显然将数列中最小的数扩大更能让乘积变大,于是遍历找出最小的数然后求乘积即可。

#include<stdio.h>
int main() 
{
	int t;
	scanf("%d", &t);
	while (t--) 
	{
		int n, i, min, j, p = 1;
		scanf("%d", &n);
		int a[10];
		for (i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
			if (i == 0 || a[i] < min)
			{
				min = a[i];
				j = i;
			}
		}
		a[j]++;
		for (i = 0; i < n; i++)
		{
			p *= a[i];
		}
		printf("%d\n", p);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值