Submit | All submissions | Best solutions | Back to list |
EIUHALF - Divide in Half |
You are given a list of N items. Each item has a value ai (a1, a2,..., an).
Let’s split these items into two subsets such that the absolute difference between their sums is minimum. Calculate this difference.
Input
- The first line contains an integer N (1 ≤ N ≤ 100).
- The second line has N integers a1, a2..., an respectively (0 ≤ ai ≤ 107 and 0 ≤ a1+a2+…+an ≤ 107).
Output
Print minimum difference between two sets.
Sample
Input |
Output |
7 1 2 3 4 5 6 7 |
0 |
4 1 11 5 6 |
1 |
Added by: | Ha Minh Ngoc |
Date: | 2023-08-29 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |