您的位置:首页 > 科技 > IT业 > 免费源码资源站_创建站点的基本步骤_免费的网站申请_石家庄seo外包的公司

免费源码资源站_创建站点的基本步骤_免费的网站申请_石家庄seo外包的公司

2025/5/9 6:33:29 来源:https://blog.csdn.net/jj12345jj198999/article/details/147543137  浏览:    关键词:免费源码资源站_创建站点的基本步骤_免费的网站申请_石家庄seo外包的公司
免费源码资源站_创建站点的基本步骤_免费的网站申请_石家庄seo外包的公司

time limit per test

2 seconds

memory limit per test

256 megabytes

The pink soldiers have given you a sequence aa consisting of nn positive integers.

You must repeatedly perform the following operation until there is only 11 element left.

  • Choose two distinct indices ii and jj.
  • Then, choose a positive integer value xx such that there exists a non-degenerate triangle∗∗ with side lengths aiai, ajaj, and xx.
  • Finally, remove two elements aiai and ajaj, and append xx to the end of aa.

Please find the maximum possible value of the only last element in the sequence aa.

∗∗A triangle with side lengths aa, bb, cc is non-degenerate when a+b>ca+b>c, a+c>ba+c>b, b+c>ab+c>a.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105).

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000) — the elements of the sequence aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output the maximum possible value of the only last element on a separate line.

Example

Input

Copy

 

4

1

10

3

998 244 353

5

1 2 3 4 5

9

9 9 8 2 4 4 3 5 3

Output

Copy

10
1593
11
39

Note

On the first test case, there is already only one element. The value of the only last element is 1010.

On the second test case, aa is initially [998,244,353][998,244,353]. The following series of operations is valid:

  1. Erase a2=244a2=244 and a3=353a3=353, and append 596596 to the end of aa. aa is now [998,596][998,596].
  2. Erase a1=998a1=998 and a2=596a2=596, and append 15931593 to the end of aa. aa is now [1593][1593].

It can be shown that the only last element cannot be greater than 15931593. Therefore, the answer is 15931593.

解题说明:此题是一道数学题,采用贪心算法,找规律能发现为了保证添加的数尽可能大,则为每次从数列中取的两个数之和减去1。这样计算下来就是减去n-1个1(因为去掉两个数又增加了一个数,等于每次只少了一个数,最后还保留一个数)。所以直接求和即可。

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com