#P3878. [TJOI2010] 分金币

    ID: 2815 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2010各省省选O2优化模拟退火进制天津

[TJOI2010] 分金币

Description

There are nn coins, which may have different values. The value of the ii-th coin is viv_i.

Now we need to split them into two parts such that the difference in the numbers of coins does not exceed 11. What is the minimum possible difference between the total values of the two parts?

Input Format

This problem contains multiple sets of testdata within a single test point.

The first line contains a positive integer TT, denoting the number of test cases in this test point.

For each test case:

Each test case consists of two lines.

The first line contains an integer nn, denoting the number of coins.

The second line contains nn integers. The ii-th integer denotes the value viv_i of the ii-th coin.

Output Format

For each test case, output one line with a single integer denoting the answer.

2
3
2 2 4
4
1 2 3 6

0
2

Hint

Constraints

  • For 30%30\% of the data, it is guaranteed that 1vi10001 \leq v_i \leq 1000.
  • For 100%100\% of the testdata, it is guaranteed that 1T201 \leq T \leq 20, 1n301 \leq n \leq 30, 1vi2301 \leq v_i \leq 2^{30}.

Translated by ChatGPT 5