Given a set A
containing n
positive integers, how can I find the smallest integer >= 0 that can be obtained using all the elements in the set. Each element can be can be either added or subtracted to the total.
Few examples to make this clear.
A = [ 2, 1, 3]
Result = 0
(2 + 1 - 3)
A = [1, 2, 0]
Result = 1
(-1 + 2 + 0)
A = [1, 2, 1, 7, 6]
Result = 1
(1 + 2 - 1 - 7 + 6)