Problems > The Fairest Cut

The Fairest Cut

Difficulty: 1600 6000 ms 128 MB

dp

Split the multiset into two groups minimizing the absolute difference of their sums. Print that minimum difference.

Input: the first line has N; the second line has N positive integers.

Output: the minimum achievable difference.

Constraints:

  • 1 ≤ N ≤ 100
  • 1 ≤ ai ≤ 1000

Sample Tests

Input 1
4
1 6 11 5
Output 1
1
Input 2
1
7
Output 2
7

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.