TheFor $n=1$, clearly $x_1=S$; for $n=2$, we can also show that $x_1=x_2=S/2$. So we'll take $n\ge 3$ from now on. The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = \frac{\partial F}{\partial x_i} + \lambda = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on the sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$$$ F(\mathbf{x}) = -\frac{2n}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$. If $S=n/3$, then the minimum occurs when all $x_i=1/3$, and $F=-2/27$. Otherwise, So we need to maximizewant the maximum of the term $$ \left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|, $$ which can only happenoccur when $k=0$, or when $|2k-n|=1$ (ifor $k=(n\pm 1)/2$, if $n$ is odd), or when $|2k-n|=2$ (ifor $k=n/2 \pm 1$, if $n$ is even). Putting everything together, the structure of the minimizer is just going to depend on $\alpha \equiv |3S-n|$, and on $n$. We have $$ F_{\text{min}} = -\frac{2n}{27} - \frac{\alpha}{27} \max({ |3-\alpha^2 / n^2|, |3- \alpha^2 / P^2 |}), $$ where $P=1$ if $n$ is odd and $P=2$ if $n$ is even. If the first term is the maximum, then all $x_i$ are equal. If the second term is the maximum, then the $x_i$ assume two different values, with about half equal to each. When is $|3-\alpha^2/n^2| \ge |3 - \alpha^2/P^2|$? Certainly this holds whenever $\alpha \le P\sqrt{3}$. It also holds when $\alpha < P\sqrt{6}$ and $n \ge (P\alpha) / \sqrt{6P^2 - \alpha^2}$. These are the cases where all $x_i$ are equal. In all other cases... specifically, $\alpha \ge P\sqrt{6}$, or $\alpha > P\sqrt{3}$ and $n < (P\alpha)/\sqrt{6P^2-\alpha^2}$... the $x_i$ assume two distinct values.
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = \frac{\partial F}{\partial x_i} + \lambda = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on the sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$. If $S=n/3$, then the minimum occurs when all $x_i=1/3$, and $F=-2/27$. Otherwise, we need to maximize the term $$ \left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|, $$ which can only happen when $k=0$, or when $|2k-n|=1$ (if $n$ is odd), or when $|2k-n|=2$ (if $n$ is even).
For $n=1$, clearly $x_1=S$; for $n=2$, we can also show that $x_1=x_2=S/2$. So we'll take $n\ge 3$ from now on. The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = \frac{\partial F}{\partial x_i} + \lambda = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on the sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2n}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$. So we want the maximum of the term $$ \left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|, $$ which can occur when $k=0$, or when $|2k-n|=1$ (or $k=(n\pm 1)/2$, if $n$ is odd), or when $|2k-n|=2$ (or $k=n/2 \pm 1$, if $n$ is even). Putting everything together, the structure of the minimizer is just going to depend on $\alpha \equiv |3S-n|$, and on $n$. We have $$ F_{\text{min}} = -\frac{2n}{27} - \frac{\alpha}{27} \max({ |3-\alpha^2 / n^2|, |3- \alpha^2 / P^2 |}), $$ where $P=1$ if $n$ is odd and $P=2$ if $n$ is even. If the first term is the maximum, then all $x_i$ are equal. If the second term is the maximum, then the $x_i$ assume two different values, with about half equal to each. When is $|3-\alpha^2/n^2| \ge |3 - \alpha^2/P^2|$? Certainly this holds whenever $\alpha \le P\sqrt{3}$. It also holds when $\alpha < P\sqrt{6}$ and $n \ge (P\alpha) / \sqrt{6P^2 - \alpha^2}$. These are the cases where all $x_i$ are equal. In all other cases... specifically, $\alpha \ge P\sqrt{6}$, or $\alpha > P\sqrt{3}$ and $n < (P\alpha)/\sqrt{6P^2-\alpha^2}$... the $x_i$ assume two distinct values.
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = 3x_i^2 - 2x_i + \lambda = 0, $$$$ \frac{\partial G}{\partial x_i} = \frac{\partial F}{\partial x_i} + \lambda = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on the sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$. If $S=n/3$, then the minimum occurs when all $x_i=1/3$, and $F=-2/27$. Otherwise, we need to maximize the term $$ \left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|, $$ which can only happen when $k=0$, or when $|2k-n|=1$ (if $n$ is odd), or when $|2k-n|=2$ (if $n$ is even).
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$.
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = \frac{\partial F}{\partial x_i} + \lambda = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on the sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$. If $S=n/3$, then the minimum occurs when all $x_i=1/3$, and $F=-2/27$. Otherwise, we need to maximize the term $$ \left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|, $$ which can only happen when $k=0$, or when $|2k-n|=1$ (if $n$ is odd), or when $|2k-n|=2$ (if $n$ is even).
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. If Since $$ \frac{\partial G}{\partial x_i} = 3x_i^2 - 2x_i + \lambda = 0, $$ then we mustwe have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so we also need $\lambda \le 1/3$). Moreover, we must haveneed $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ F(\mathbf{x}) = -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda}. $$$$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$.
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$. If $$ \frac{\partial G}{\partial x_i} = 3x_i^2 - 2x_i + \lambda = 0, $$ then we must have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so we also need $\lambda \le 1/3$). Moreover, we must have $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ F(\mathbf{x}) = -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda}. $$
The theory of Lagrange multipliers says that the minima of your function (for fixed $n$ and $S$) must be found among the saddle points of $$ G(\mathbf{x}, \lambda) = F(\mathbf{x}) + \lambda \left(\sum_i x_i - S\right), $$ where $F(\mathbf{x})=\sum_i (x_i^3 - x_i^2)$ is what you want to minimize. Since $$ \frac{\partial G}{\partial x_i} = 3x_i^2 - 2x_i + \lambda = 0, $$ we have $$ x_i = \frac{2 \pm \sqrt{4 - 12\lambda}}{6} = \frac{1\pm\sqrt{1-3\lambda}}{3} $$ for each $i$ (and so $\lambda \le 1/3$). Moreover, we need $$ \frac{\partial G}{\partial \lambda} = \sum_i x_i - S = 0. $$ If $0 \le k \le n$ of the $x_i$ are equal to $(1+\sqrt{1-3\lambda})/3$, and the remaining $n-k$ are equal to $(1-\sqrt{1-3\lambda})/3$, then this latter constraint gives $$ k(1 + \sqrt{1-3\lambda}) + (n-k)(1-\sqrt{1-3\lambda})=n + (2k-n)\sqrt{1-3\lambda}=3S, $$ or $$ \lambda = \frac{1}{3}\left(1 - \left(\frac{3S-n}{2k-n}\right)^2\right). $$ After some algebra, then, each $x_i$ satisfies $$ x_i^3 - x_i^2 = x_i^2(1-x_i) = \frac{1}{27}\left(-2 \pm (2+3\lambda)\sqrt{1-3\lambda}\right), $$ depending on the chosen sign for that $i$; and if $k$ are positive and the rest are negative, we finally arrive at $$ \begin{eqnarray} F(\mathbf{x}) &=& -\frac{2n}{27} + \frac{2k-n}{27}(2 + 3\lambda)\sqrt{1-3\lambda} \\ &=& -\frac{2n}{27}+\frac{1}{27}\left(3 - \left(\frac{3S-n}{2k-n}\right)^2\right)(3S-n)\cdot\text{sgn}(2k-n). \end{eqnarray} $$ This needs to be minimized over $k \in \{0,1,\ldots,n\} \setminus \{n/2\}$. We'll always choose $k>n/2$ or $k<n/2$ depending on sign of the resulting contribution to $F$, so in fact we can minimize $$ F(\mathbf{x}) = -\frac{2}{27} - \frac{1}{27}\cdot\left|3 - \left(\frac{3S-n}{2k-n}\right)^2\right|\cdot\left|3S-n\right| $$ over $0 \le k < n/2$.