A. Blackboard List

给定一个经过特定操作后的整数列表,该操作涉及计算列表中任意两个数的差值的绝对值并替换原来的数,目标是恢复出初始的两个数字之一。题目保证输入是通过这个过程生成的。解决方案包括寻找列表中的最小负数或最大正数作为初始数字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Blackboard List

Two integers were written on a blackboard. After that, the following step was carried out n−2n−2 times:

  • Select any two integers on the board, and write the absolute value of their difference on the board.

After this process was complete, the list of nn integers was shuffled. You are given the final list. Recover one of the initial two numbers. You do not need to recover the other one.

You are guaranteed that the input can be generated using the above process.

Input

The first line of the input contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (3≤n≤1003≤n≤100) — the size of the final list.

The next line of each test case contains nn integers a1,a2,…ana1,a2,…an (−109≤ai≤109−109≤ai≤109) — the shuffled list of numbers written on the blackboard.

It is guaranteed that the input was generated using the process described above.

Output

For each test case, output a single integer xx — one of the two initial numbers on the blackboard.

If there are multiple solutions, print any of them.

Example

input

Copy

 

9

3

9 2 7

3

15 -4 11

4

-9 1 11 -10

5

3 0 0 0 3

7

8 16 8 0 8 16 8

4

0 0 0 0

10

27 1 24 28 2 -1 26 25 28 27

6

600000000 800000000 0 -200000000 1000000000 800000000

3

0 -1000000000 1000000000

output

Copy

9
11
-9
3
8
0
-1
600000000
0

Note

For the first test case, aa can be produced by starting with either 99 and 22, and then writing down |9−2|=7|9−2|=7, or starting with 99 and 77 and writing down |9−7|=2|9−7|=2. So 22, 77, and 99 are all valid answers, because they all appear in at least one valid pair.

For the second test case, we can show that the two initial numbers must have been −4−4 and 1111.

For the fourth test case, the starting numbers could have been either 33 and 33, or 33 and 00, so 33 and 00 are both valid answers.

For the fifth test case, we can show that the starting numbers were 88 and 1616.

        思路:

        因为是差的绝对值, 所以无论如何都不可能得到负数,。故如果含有负数,则输出最小的负数。

        另外,求差的时候, 都不会从小求到大,所以原始的两个数字里面肯定有最大的正整数。则应该输出最大的正整数。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        int a[n];
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a,a+n);
        cout << (a[0] < 0 ? a[0] : a[n-1]) << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值