Problem7496--[CSES Problem Set] Apple Division

7496: [CSES Problem Set] Apple Division

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

There are $n$ apples with known weights. 
Your task is to divide the apples into two groups so that the difference between the weights of the groups is minimal.

Input

The first input line has an integer $n$: the number of apples.
The next line has $n$ integers $p_1,p_2,…,p_n$: the weight of each apple.

Output

Print one integer: the minimum difference between the weights of the groups.

Constraints

$1 \leq n \leq 20$
$1 \leq p_i \leq 10^9$

Sample 1 Input

5
3 2 7 4 1

Sample 1 Output

1
Group 1 has weights 2, 3 and 4 (total weight 9), and group 2 has weights 1 and 7 (total weight 8).

HINT

相同题目:CSES 1623

Source/Category