Constrained maximization in L dimensions

The problem is like

$max_{\mathbf{x} } \:u(x_1, x_2, ..., x_L) = - \sum_{i =1}^{L} \mid x_i - a_i\mid$,

$s.t. \sum_i^L x_i \leq C$,

for each $i$, $a_i > 0$ is a scalar;

$C$ is a constant that is strictly greater than $0$;

$\mathbf{x} = (x_1, x_2, ..., x_L)\in {\mathbf R}^{L}_{+}$. Characterize the optimal $\mathbf{x}$ as a function of $C$ or $a_i$.

Hint: to solve the problem we should discuss the cases when $C \le \sum_i a_i$ and $C \ge \sum_i a_i$.

Thank you!

The solution to your problem is easy in the case $C \ge \sum_i a_i$. Then you can choose $x_i = a_i$ and you are done with the maximiation since $0 \geq u(\mathbf{x}) = 0$.

For the case $C < \sum_i a_i$ the choice $x_i = a_i$ is not feasible. In this case it does not make sence to choose $x_i > a_i$ and we can reformulate $u(\mathbf{x}) = - \sum ( a_i - x_i)$. From the latter formulation it follows that the goal is to choose $\sum x_i$ as large as possible to maximize $u(\mathbf{x})$. As $\sum x_i \leq C$ we have $u(\mathbf{x})= C - \sum a_i$.