欢迎光临散文网 会员登陆 & 注册

CF 1822B. Karina and Array

2023-08-18 08:38 作者:您是打尖儿还是住店呢  | 我要投稿

Karina has an array of n integers a1,a2,a3,…,an. 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⋅5, 5⋅7, 7⋅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≤t≤104) — the number of test cases.


The description of the test cases follows.

The first line of a test case contains an integer n (2≤n≤2⋅105) — the length of the array a.

The second line of a test case contains n integers a1,a2,a3,…,an(−109≤ai≤109) — the elements of the array a.


The sum of all values of n across all test cases does not exceed 2⋅105.


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.

-----------------------------------------------

Karina 有一个由 n 个整数组成的数组 a1,a2,a3,…,an。 她喜欢数字相乘,因此她认为一对数字的美妙之处在于它们的乘积。 而数组的美感就是数组中一对相邻元素的最大美感。


例如,对于n=4,a=[3,5,7,4],数组的美感为max

(3⋅5, 5⋅7, 7⋅4) = 最大值(15, 35, 28) = 35。

卡琳娜希望她的阵列尽可能漂亮。 为了实现她的目标,她可以从数组中删除一些元素(可能为零)。 卡琳娜 (Karina) 删除她想要删除的所有元素后,数组必须至少包含两个元素。


不幸的是,卡琳娜没有足够的时间来完成她的所有任务,因此她要求您计算她通过删除任意数量的元素(可能为零)可以获得的数组的最大美感。


输入

输入的第一行包含一个整数 t (1≤t≤104) — 测试用例的数量。


测试用例的描述如下。

测试用例的第一行包含一个整数 n (2≤n≤2⋅105) — 数组 a 的长度。

测试用例的第二行包含 n 个整数 a1,a2,a3,…,an(−109≤ai≤109) — 数组 a 的元素。


所有测试用例中 n 的所有值的总和不超过 2⋅105。


输出

输出t个整数,每个整数都是对应测试用例的答案——Karina可以获得的数组的最大美感。

---------------------

就是计算乘积的最大值,因为负负得正,所以有可能是负数,所以这里面要比较2个值,最大的两个的乘积跟最小的两个的乘积的大小。

下面是代码:


CF 1822B. Karina and Array的评论 (共 条)

分享到微博请遵守国家法律