The problem is to solve dynamic programming problem $$\sum_{t=1}^T\left(\frac{t^3}{3}+\frac{t^2}{2}\right)a_t^2 \to \max$$ where $\sum_{t=1}^T a_t =c$, and $a_t$ is assumed to be $\geq 0$. It is expected to introduce $w_t = \sum_{i=1}^ta_i$ to solve it. My ideas: By introducing this variable, we get $$\sum_{t=1}^T\left(\frac{t^3}{3}+\frac{t^2}{2}\right)(w_t - w_{t-1})^2 \to \max$$ subject to $ w_T = c $. Seems like here it is relevant to form a Lagrange function $$L(w_1,...,w_T,\lambda ) = \sum_{t=1}^T\left(\frac{t^3}{3}+\frac{t^2}{2}\right)(w_t - w_{t-1})^2 + \lambda (w_T - c)$$ Here $w_0$ which arises under summation symbol should be treated as 0. But from partial derivatives I can't get a solution:
$$\frac{\partial L}{\partial w_t} =2\left(\frac{t^3}{3}+\frac{t^2}{2}\right)(w_t-w_{t-1}) - 2 \left(\frac{(t+1)^3}{3}+\frac{(t+1)^2}{2}\right)(w_{t+1}-w_t)=0$$
$$\frac{\partial L}{\partial w_T} = 2\left(\frac{T^3}{3}+\frac{T^2}{2}\right)(w_T-w_{T-1})+\lambda=0$$
$$\frac{\partial L}{\partial \lambda} = w_T - c=0$$
So, we have $w_T=c$ which we can substitute into second condition but I don't know what to do next.
Thank you in advance.