<p>Note that $T=S$ and $T=\emptyset$ are trivial solutions.</p>

<p>With the constraints $T \neq \emptyset$ and $S\setminus T \neq \emptyset$ the problem seems (unless the proof below is wrong :-) NP-complete. A possible reduction is from PARTITION: given a set $A$ of $n$ positive integers $A=a_1,..a_n$, can $A$ be partitioned in two sets $A = A_1 \cup A_2$ such that $\sum_{a_i\in A_1} a_i = \sum_{a_j \in A_2} a_j$?</p>

<p>Let $M = \sum_{a_i \in A}a_i$; without loss of generality we can assume that $M$ is even.</p>

<p>You can pick $S = A \cup \{a_{n+1}, a_{n+2}\}$ with $a_{n+1}= a_{n+2}=-M/2$; so we have $\sum_{s \in S}s = 0$ (right hand side of the equation of your problem). </p>

<p>The original PARTITION problem has a solution if and only if your problem has a solution.</p>

<p>$(\Leftarrow)$ Suppose that there exists $T$ such that $|\sum_{t\in T}t-\sum_{s\in S\setminus T}s|\le\sum_{s\in S}s$ = 0. So the absolute value of the difference of the sums is zero: $|\sum_{t\in T}t-\sum_{s\in S\setminus T}s| = 0$ <br> $T$ cannot contain both $a_{n+1}$ and $a_{n+2}$, otherwise  $|\sum_{t\in T}t-\sum_{s\in S\setminus T}s| &gt; 0$ because at least one element $a_i&gt;0$ must be contained in $S \setminus T$ and $|-M/2 -M/2 - a_i| &gt; M$. For the same reason $S \setminus T$ cannot contain both $a_{n+1}$ and $a_{n+2}$. So $a_{n+1} \in T$ and $a_{n+2} \in S \setminus T$, and their contribution to the absolute value of the difference of the sums is $0$. So the remaining elements must be partitioned in such a way that the sum of the elements in $T$ equals the sum of elements in $S \setminus T$ in order to have an absolute value of the difference of the sums equal to $0$.</p>

<p>$(\Rightarrow)$ If the original partition problem has a solution, then it is easy to see that if $T = A_1 \cup a_{n+1}$ we get an absolute value of the difference of the sums equal to $0$.</p>

CC BY-SA 3.0
2014-03-20T11:35:10.027Z
Thank you. Your proof works if we add that we can assume wlog that $S$ consists of nonnegative numbers (which we can).
J Bausch
CC BY-SA 3.0
2014-03-17T19:31:05.553Z
2014-03-17T19:31:05.553Z
Marzio De Biasi
<p>I've read that this SE is for research-level CS questions; this is certainly research level, just not my field of research, so it is hard for me to assess how difficult the question really is. So in case this is well-known and easy, I'd still be grateful for a hint or a reference. Thanks!</p>

<p>So here is the question:
Given a multiset $S$ of integers (or rationals), does there exist a multi-subset $T\subsetneq S$ such that $|\sum_{t\in T}t-\sum_{s\in S\setminus T}s|\le\sum_{s\in S}s$?</p>

<p>In case we replace the rhs with some constant $l\ge0$, this reduces to the subset sum decision variant, which is NP hard. <strong>But is this variant still NP-hard?</strong></p>

<p>Thanks!
- Josely</p>

CC BY-SA 3.0
2014-03-17T16:14:03.580Z
Can't you just use scaling ? Given an instance $(S, k)$, construct a new instance $S'$ where all elements have been scaled by $\sum_{s \in S} s/k$.
Suresh Venkat
CC BY-SA 3.0
2014-03-20T11:36:09.330Z
@SureshVenkat: I don't think that helps, since it scales both sides of the inequality.
J Bausch
<cc.complexity-theory>
Subset Sum Variant still NP hard?
J Bausch
# Subset Sum Variant still NP hard?

(Asked by: username_0 on 2014-03-17)

I've read that this SE is for research-level CS questions; this is certainly research level, just not my field of research, so it is hard for me to assess how difficult the question really is. So in case this is well-known and easy, I'd still be grateful for a hint or a reference. Thanks!

So here is the question:
Given a multiset $S$ of integers (or rationals), does there exist a multi-subset $T\subsetneq S$ such that $|\sum\_{t\in T}t-\sum\_{s\in S\setminus T}s|\le\sum\_{s\in S}s$?

In case we replace the rhs with some constant $l\ge0$, this reduces to the subset sum decision variant, which is NP hard. **But is this variant still NP-hard?**

Thanks!
- Josely

**Tags:** cc.complexity-theory

> **Comments:**
> **username_1**: Can't you just use scaling ? Given an instance $(S, k)$, construct a new instance $S'$ where all elements have been scaled by $\sum_{s \in S} s/k$.  
> **username_0**: @SureshVenkat: I don't think that helps, since it scales both sides of the inequality.  

---

## 1 answers

### Answer by username_2 on 2014-03-17. Score: 3 | Accepted answer

Note that $T=S$ and $T=\emptyset$ are trivial solutions.

With the constraints $T \neq \emptyset$ and $S\setminus T \neq \emptyset$ the problem seems (unless the proof below is wrong :-) NP-complete. A possible reduction is from PARTITION: given a set $A$ of $n$ positive integers $A=a\_1,..a\_n$, can $A$ be partitioned in two sets $A = A\_1 \cup A\_2$ such that $\sum\_{a\_i\in A\_1} a\_i = \sum\_{a\_j \in A\_2} a\_j$?

Let $M = \sum\_{a\_i \in A}a\_i$; without loss of generality we can assume that $M$ is even.

You can pick $S = A \cup \{a\_{n+1}, a\_{n+2}\}$ with $a\_{n+1}= a\_{n+2}=-M/2$; so we have $\sum\_{s \in S}s = 0$ (right hand side of the equation of your problem).

The original PARTITION problem has a solution if and only if your problem has a solution.

$(\Leftarrow)$ Suppose that there exists $T$ such that $|\sum\_{t\in T}t-\sum\_{s\in S\setminus T}s|\le\sum\_{s\in S}s$ = 0. So the absolute value of the difference of the sums is zero: $|\sum\_{t\in T}t-\sum\_{s\in S\setminus T}s| = 0$   
 $T$ cannot contain both $a\_{n+1}$ and $a\_{n+2}$, otherwise $|\sum\_{t\in T}t-\sum\_{s\in S\setminus T}s| > 0$ because at least one element $a\_i>0$ must be contained in $S \setminus T$ and $|-M/2 -M/2 - a\_i| > M$. For the same reason $S \setminus T$ cannot contain both $a\_{n+1}$ and $a\_{n+2}$. So $a\_{n+1} \in T$ and $a\_{n+2} \in S \setminus T$, and their contribution to the absolute value of the difference of the sums is $0$. So the remaining elements must be partitioned in such a way that the sum of the elements in $T$ equals the sum of elements in $S \setminus T$ in order to have an absolute value of the difference of the sums equal to $0$.

$(\Rightarrow)$ If the original partition problem has a solution, then it is easy to see that if $T = A\_1 \cup a\_{n+1}$ we get an absolute value of the difference of the sums equal to $0$.

> **Comments:**
> **username_0**: Thank you. Your proof works if we add that we can assume wlog that $S$ consists of nonnegative numbers (which we can).  

---

