题目描述
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given an array $A$ of size $N$. Find the maximum value of the expression $a * b + a - b$ where $a$ and $b$ are $2$ distinct elements of the array.
------ Input: ------
First line will contain $T$, number of testcases. Then the testcases follow.
Each testcase contains of two lines of input.
First line will contain $N$, number of elements of the array.
Second line contains $N$ space separated integers, elements of the array $A$.
------ Output: ------
For each testcase, output in a single line answer to the problem.
------ Constraints ------
$1 ≤ T ≤ 20$
$2 ≤ N ≤ 10^{5}$
$-10^{9} ≤ A_{i} ≤ 10^{9}$
----- Sample Input 1 ------
2
2
2 2
3
5 3 2
----- Sample Output 1 ------
4
17
----- explanation 1 ------
Case 1: Only possible pair is $[2, 2]$ for which answer = $2 * 2 + 2 - 2$ = $4$.
Case 2: There are six possible pairs.
For pairs $[2, 3]$ and $[3, 2]$, answer = $2 * 3 + max(2 - 3, 3 - 2)$ = $7$
For pairs $[3, 5]$ and $[5, 3]$ answer = $5 * 3 + max(3 - 5, 5 - 3)$ = $17$ and
For the pairs $[2, 5]$ and $[5, 2]$, answer = $2 * 5 + max(2 - 5, 5 - 2)$ = $13$.
So final answer is maximum of $\{7, 17, 13\}$ = $17$.
输入格式
见题面
输出格式
见题面