Convex quadratic program with linear equality constraint and bounds on variables $$\begin{array}{ll} \text{minimize} & \sum \limits_{i=1}^n x_{i}^{2}\\ \text{subject to} & \sum \limits_{i=1}^n x_{i} = m\\ & 0 \leq x_i \leq a_i\end{array}$$
I know that if the $a_i$ are large enough (i.e., greater than $\frac{m}{n}$), this is minimized when $x_i = \frac{m}{n}\ \forall i$.
I also think (but do not have a formal proof) that when some of the $a_i$ are not large enough (say $a_1,...,a_k$), then this is minimized when:
$x_i = a_i$ for $i \leq k$ and
$x_i = \frac{m -\sum \limits_{i=1}^k a_{i}}{n-k}$ for $i>k$.
Is this true? And if so could you provide a reference for this? Thanks!
 A: Yes, from the observation that moving two $x_i$ "closer together" without changing the sum—that is, if $x_i < x_j$, then replacing $x_i$ and $x_j$ with $x_i + \epsilon$ and $x_j - \epsilon$—will always reduce $\sum x_i^2$. It's easy to see this by writing $x_i + x_j = k$ and rewriting $x_i^2 + x_j^2 = x_i^2 + (k-x_i)^2 = 2 \left(x_i - \frac{k}{2}\right)^2 + \frac{k^2}{2}$, which is minimized when $x_i = k/2$ and increases with $\left|\frac{k}{2} - x_i\right|$.
This means that the (necessarily unique) arrangement of $x_i$ that gives a minimum value of $\sum x_i^2$ cannot have any $x_i$ that is less than both its corresponding $a_i$ and some other $x_j$; otherwise, there would be room to reduce $\sum x_i^2$ by raising $x_i$ and lowering $x_j$. This forces a minimum of the form that you give.
One note: it's possible for the minimizer of $\sum x_i^2$ to give $x_i = a_i$ even when $a_i > m/n$. Consider the case $m = 1$, $n = 3$, $a_1 = 0.2$, $a_2 = 0.35$, $a_3 = 1$. "Large enough" doesn't necessarily mean greater than $m/n$.
