310362: CF1822B. Karina and Array

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Karina and Arraytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Karina has an array of $n$ integers $a_1, a_2, a_3, \dots, a_n$. She loves multiplying numbers, so she decided that the beauty of a pair of numbers is their product. And the beauty of an array is the maximum beauty of a pair of adjacent elements in the array.

For example, for $n = 4$, $a=[3, 5, 7, 4]$, the beauty of the array is $\max$($3 \cdot 5$, $5 \cdot 7$, $7 \cdot 4$) = $\max$($15$, $35$, $28$) = $35$.

Karina wants her array to be as beautiful as possible. In order to achieve her goal, she can remove some elements (possibly zero) from the array. After Karina removes all elements she wants to, the array must contain at least two elements.

Unfortunately, Karina doesn't have enough time to do all her tasks, so she asks you to calculate the maximum beauty of the array that she can get by removing any number of elements (possibly zero).

Input

The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The description of the test cases follows.

The first line of a test case contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the array $a$.

The second line of a test case contains $n$ integers $a_1, a_2, a_3, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) — the elements of the array $a$.

The sum of all values of $n$ across all test cases does not exceed $2 \cdot 10^5$.

Output

Output $t$ integers, each of which is the answer to the corresponding test case — the maximum beauty of the array that Karina can get.

ExampleInput
7
4
5 0 2 1
3
-1 1 0
5
2 0 -1 -4 0
6
-8 4 3 7 1 -9
6
0 3 -2 5 -4 -4
2
1000000000 910000000
7
-1 -7 -2 -5 -4 -6 -3
Output
10
0
4
72
16
910000000000000000
42
Note

In the first test case of the example, to get the maximum beauty, you need to remove the $2$-nd element.

In the second and third test cases of the example, there is no need to remove any elements to achieve maximum beauty.

In the fourth test case of the example, you need to leave only the first and last elements.

Input

题意翻译

## 题目描述 Karina 有一个 $n$ 个整数的数组 $a_1,a_2,a_3,\cdots,a_n$。她还喜欢将数字乘在一起,所以她认为一对数字的美在于它们的乘积。数组的美就是数组中相邻的一对元素的最大美。 例如,对于 $n = 4$,$a =[3,5,7,4]$,数组的美妙之处是 $max(3\times5,5 \times 7,7 \times 4) = max (15, 35, 28) = 35$。 Karina 希望她的阵列尽可能的漂亮。为了实现她的目标,她可以从数组中删除一些元素(可能为零)。在 Karina 删除她想要的所有元素后,数组必须包含至少两个元素。 不幸的是,Karina 没有足够的时间来完成她的所有任务,所以她要求你计算她通过删除任意数量的元素(可能为零)所能获得的数组的最大美感。 ## 输入格式 **本题有多组数据**。 第一行一个整数 $t(1 \leq t \leq 10^4)$,表示数据组数。 对于每组数据: 第一行为一个整数 $n(2 \times 10^5)$,表示数组 $a$ 的长度。 第一行包含 $n$ 个整数 $a_1,a_2,a_3,\cdots,a_n(-10^9 \leq a_i \leq 10^9)$,代表数组 $a$ 的元素。 所有测试数据中所有 $n$ 值的总和不超过 $2 \times 10^5$。 ## 输出格式 对于每组测试数据: 输出 Karina 可以得到数组的最大美感。 感谢@[ULSG_XBaiC](https://www.luogu.com.cn/user/925577) 的翻译。

Output

题目大意:
卡琳娜有一个包含n个整数的数组a_1, a_2, a_3, ..., a_n。她喜欢乘法,所以她定义了一对数字的“美”是它们的乘积。一个数组的“美”是数组中任意两个相邻元素的最大“美”。例如,对于n=4,a=[3, 5, 7, 4],数组的“美”是max(3*5, 5*7, 7*4) = max(15, 35, 28) = 35。卡琳娜希望她的数组尽可能“美”,为了达到这个目标,她可以删除数组中的一些元素(可能为零个)。删除元素后,数组中必须至少还剩两个元素。要求计算删除一些元素后,数组能达到的最大“美”。

输入数据格式:
第一行包含一个整数t,表示测试用例的数量。
每个测试用例的第一行包含一个整数n,表示数组a的长度。
每个测试用例的第二行包含n个整数a_1, a_2, a_3, ..., a_n,表示数组a的元素。

输出数据格式:
对于每个测试用例,输出一行,包含一个整数,表示删除一些元素后,数组能达到的最大“美”。题目大意: 卡琳娜有一个包含n个整数的数组a_1, a_2, a_3, ..., a_n。她喜欢乘法,所以她定义了一对数字的“美”是它们的乘积。一个数组的“美”是数组中任意两个相邻元素的最大“美”。例如,对于n=4,a=[3, 5, 7, 4],数组的“美”是max(3*5, 5*7, 7*4) = max(15, 35, 28) = 35。卡琳娜希望她的数组尽可能“美”,为了达到这个目标,她可以删除数组中的一些元素(可能为零个)。删除元素后,数组中必须至少还剩两个元素。要求计算删除一些元素后,数组能达到的最大“美”。 输入数据格式: 第一行包含一个整数t,表示测试用例的数量。 每个测试用例的第一行包含一个整数n,表示数组a的长度。 每个测试用例的第二行包含n个整数a_1, a_2, a_3, ..., a_n,表示数组a的元素。 输出数据格式: 对于每个测试用例,输出一行,包含一个整数,表示删除一些元素后,数组能达到的最大“美”。

加入题单

上一题 下一题 算法标签: