#K73882. Minimum Skill Difference Partition

    ID: 34074 Type: Default 1000ms 256MiB

Minimum Skill Difference Partition

Minimum Skill Difference Partition

You are given a set of participants, each with a given skill level. Your task is to partition these participants into two teams such that the absolute difference between the total skill levels of the two teams is minimized.

Formally, given an integer \(n\) and a list of \(n\) integers \(s_1, s_2, \dots, s_n\) representing the skill levels, find a partition of the set into two disjoint subsets \(A\) and \(B\) (with \(A \cup B = \{s_1, s_2, \dots, s_n\}\)) such that the value

[ |\sum_{s \in A} s - \sum_{s \in B} s| ]

is minimized. This minimum value is what you need to output.

Example:

Input:
4
10 20 15 25

Output: 0

</p>

In this example, one possible optimal partition is \(A = \{10, 15\}\) and \(B = \{20, 25\}\), both summing to 25, so the difference is 0.

inputFormat

The input is given in two lines:

  • The first line contains a single integer \(n\) (\(n \ge 2\)), the number of participants.
  • The second line contains \(n\) space-separated integers representing the skill levels of the participants.

outputFormat

Output a single integer representing the minimum possible absolute difference between the total skill levels of the two teams.

## sample
4
10 20 15 25
0