Let X=∑i=1niai, Y=∑i=1niai. We have to find the maximum possible value of the quantity XY2.
First, we note that for each i∈{1,2,…,n}, i+in≤n+1 holds. This follows since (n+1)−(i+in)=i1(i−1)(n−i)≥0. Using this fact we get
X+nY=i=1∑n(i+in)ai≤i=1∑n(n+1)ai=n+1.
We then apply the inequality on additive and multiplicative means to the three quantities X, 2nY, 2nY to obtain
X⋅2nY⋅2nY≤(3X+nY)3≤(3n+1)3=27(n+1)3,
from which we conclude that XY2≤27n24(n+1)3 holds.
On the other hand, by choosing
a1=3(n−1)2n−1,a2=⋯=an−1=0,an=3(n−1)n−2
we get XY2=27n24(n+1)3, which implies that 27n24(n+1)3 is the desired maximum value.