Given a set of nonnegative numbers, put $\pm$ between them to minimize the magnitude of the result

84 Views Asked by At

Let's say I have a finite set of non-negative numbers.

I have to put $+$ or $-$ between the numbers, in order to minimize the absolute sum.(i.e the sum has to be closest to 0)

For example: the set: $8$, $4.5$, $1$, $4$, then the solution: $-8 + 4.5 -1 +4$, which gives absolute sum of $0.5$ - which is the smallest possible.

No doubt, that it can be done by checking all the options which is $2^n$ - my question whether there is more efficient way of solving the case.