I put this problem in an old team competition I organized. It is not simple, and I asked only for the case where n is even, now I’ll show you the complete version.
Let be reals in an interval of lenght 1. Find the maximum value of
Now, let’s treat as constants and let be the variable.
We notice
This is a quadratic function and the coefficient of the quadratic term is positive.
Since the function is convex, the maximum is reached at or at .
By symmetry, we can apply the same reasoning to all the numbers. Hence let’s say that we have r terms equal to a and n-r terms equal to a+1.
We have that the maximum is:
Expanding and simplifying leads to:
The product of two numbers with constant sum is maximum when their difference is minimal. Hence, the maximum is: