logo AlgoBeat OnlineJudge
登录 注册

#209482. [ICPC 2018 Qingdao R] Soldier Game

内存限制:256 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

DreamGrid and BaoBao are playing a game. There are soldiers in the game, numbered from to . The -th soldier has a power value of . DreamGrid and BaoBao are going to divide the soldiers into several teams according to the rules below:

  • A team must consist of 1 or 2 soldiers.
  • Every soldier must belong to exactly 1 team.
  • If a team consists of two soldiers (let's say they are the -th and the -th soldier), there must be .

The power value of a team is defined as the sum of the team members' power values. For the sake of fairness, they want to minimize the difference between the maximum team power value and the minimum team power value after the division. You are asked to find the minimum difference.

输入格式

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer (), indicating the number of soldiers.

The second line contains integers (), where indicates the power value of the -th soldier.

It's guaranteed that the sum of in all test cases will not exceed .

输出格式

For each test case output one line containing one integer, indicating the minimum difference between the maximum team power value and the minimum team power value.

样例

样例输入 1

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

样例输出 1

1
2
0

数据范围与提示

We now explain the first sample test case. All possible divisions are listed below.

Division Difference Division Difference
[-1], [4], [2], [1], [1] 4 - (-1) = 5 [-1, 4], [2], [1], [1] 3 - 1 = 2
[-1], [4], [2], [1, 1] [-1], [4, 2], [1, 1] 6 - (-1) = 7
[-1], [4], [2, 1], [1] [-1, 4], [2], [1, 1] 3 - 2 = 1
[-1], [4, 2], [1], [1] 6 - (-1) = 7 [-1, 4], [2, 1], [1] 3 - 1 = 2

So the answer is .