Fairest Split
Split all N apples (with given weights) into two groups minimizing the absolute difference of group sums. Print that minimum difference.
Input: the first line has N; the second line has N weights.
Output: the minimum |sum1 − sum2|.
Constraints:
- 1 ≤ N ≤ 16
- 1 ≤ wi ≤ 109
Sample Tests
Input 1
5 3 2 7 4 1
Output 1
1
Input 2
1 5
Output 2
5
Discussion (opens after you solve — no spoilers before)
No comments yet.