Partition of a set of integer into 3 subsets of approximately equal sum I'm having a very hard time trying to figure out how to solve this problem efficiently. Let me describe how it goes:

"A hard working mom bought several fruits with different nutritional values for her 3 kids, Amelia, Jessica and Bruno. Both girls are overweight, and they are very vicious and always leave poor Bruno with nothing, so their mother decided to share the food in the following manner:


Amelia being the heaviest one gets the most amount of Nutritional Value.
Jessica gets an amount equal or less than Amelia
Bruno gets an amount equal or less than Jessica, but you need to find a way to give him the highest possible nutritional value while respecting the rule ( $A \geq J \geq B$ )"


One of the test cases given by my teacher is the following:

The fruit list has the following values { 4, 2, 1, 8, 11, 5, 1

Input:
7   -----&gt; Number of Fruits
4 2 1 8 11 5 1 ----&gt; Fruits Nutritional Values

Output:
1 11  ----&gt;  One fruit, their nutritional values sum for Amelia
5     ----&gt;  Position of the fruit in the list
3 11  ----&gt;  Three fruits, their nutritional values sum for Jessica
1 2 6 ----&gt;  Position of the fruits in the list
3 10  ----&gt;  Three fruits, their nutritional values sum for Bruno
3 4 7 ----&gt;  Position of the fruits in the list


Note: I am aware that there are several ways of diving the fruits among the kids, but it doesn't really matter as long as it follows the rule $A \geq J \geq B$.

I'm trying to make a program in C# that solves this kind of problems but I need an efficient formula to make this work. Generating all the subsets is out of the question because it is very consuming task. The list of fruits can have up to $50$ elements, $2^{50}$ is a huge number.
Let $x_i,\ i=1\ldots,n$, be the list of nutritional values of the $n$ fruits, which I assume are nonnegative integers.

You want to partition $\{1,\ldots,n\}$ into three sets $A,B,C$ to maximize the minimum of $x_A = \sum_{i\in A} x_i$, $x_B = \sum_{i \in B} x_i$, $x_C = \sum_{i \in C} x_i$.  This is a variant of the set-partitioning problem.  It is NP-complete.

However, there is a dynamic programming algorithm that is pseudo-polynomial (i.e. polynomial in $n$ and $S = \sum_{i=1}^n x_i$). Namely, for $1 \le m \le n$, $u, v \ge 0$ with $u+v \le \sum_{i=1}^m x_i$, let 
$T(m,u,v) = 1$ if there are disjoint subsets $A(m,u,v), B(m,u,v)$ of $\{1,\ldots,m\}$ 
such that $\sum_{i \in A(m,u,v)} x_i = u$ and $\sum_{i \in B(m,u,v)} x_i = v$, $T(m,u,v) = 0$ otherwise.
Thus 
$$T(1,0,0) = T(1,0,x_1) = 1,\ T(1,u,v) = 0 \text{ otherwise.}$$
For $m &gt; 1$,
$$T(m,u,v) = 1 \Longleftrightarrow T(m-1,u,v) + T(m-1,u-x_m,v) + T(m-1,u,v-x_m) \ge 1.$$

After computing all $T(m,u,v)$ using this recursion, you want to find the $(u,v)$ with $u$ as large as possible subject to $T(m,u,v) = 1$ and $u \le v \le S - u - v$.