A question on inequality of arithmetic and geometric means Let $x_i>0, i=1,...,n$ and $x_1+..+x_n=K$. From the inequality of arithmetic and geometric means, we have
$$x_1x_2...x_n\le \left( \frac{x_1+x_2..+x_n}{n} \right)^n$$
The equality holds if and only if $x_1=...=x_n=K/n$. 
My question is: if $x_i$ has its own upper or lower bound such that $x_1=...=x_n=K/n$ is impossible, when $\Pi_{i=1}^n x_i$ achieves maximum? I guess $x_i$ should approach the mean value $K/n$ as close as possible but can't prove it. Thank you.
 A: I'll do it for just 2, the generalization should be clear.  $\log x_1x_2=\log x_1 + \log x_2$. If we keep the sum $x_1 + x_2$ constant, $\mathrm dx_1=-\mathrm dx_2$ (this is essentially a Lagrange multiplier). Then $\frac{\mathrm d\log x_1x_2}{\mathrm dx_1}=\frac1{x_1}-\frac1{x_2} > 0$ if $x_1 < x_2$.  So it helps to move a bit from the big one to the little one, making both approach the mean.  If there is a limit to this, you have to quit when you hit it.
Added in response to comment:  you want to pull all the $x$'s as close to the mean as allowed and the ones farther away are highest priority.  So if $x_1\lt \alpha, x_2 \gt \beta$ you will hit one of these first.  For generic $n$ either the > or < will be the constraint and all variables subject to that one should be at the limit.  Then start with the constraints farthest from the average on the other side and satisfy them.  Finally you will have some variables you can equidistribute over.  If we have $\sum_{i=1}^6 x_i=120, x_1 \le 5, x_2 \le 10, x_3 \le 15, x_4 \ge 27, x_5\ge 30, x_6 \ge 35$, the $\gt$ ones are tougher, so $x_4 = 27, x_5 = 30, x_6 = 35$, then $x_1=5, x_2=x_3=11.5$
A: Here is my solution for generic $n$. I'm not sure whether it is correct.
Case 1: $x_i$ is possible to reach the mean value $K/n$. 
The problem actually is maximizing $\Pi_{i=1}^nx_i$ subject to $\sum_{i=1}^nx_i=K$. Use Lagrange multiplier:
$$f(x)=\sum_{i=1}^n \log x_i + \lambda \left( \sum_{i=1}^nx_i-K \right)$$
Form $\frac{\partial f}{\partial x_i}=0$ and $\frac{\partial f}{\partial \lambda}=0$, we have $x_i=K/n$ and $\lambda = -n/K$.
Case 2: Some $x_i$ is impossible to reach the mean value $K/n$.
For example, $x_i\le \alpha _i < K/n$ for $i=1,...,q$ and $x_i\ge \beta _i > K/n$ for $i=q+1,...,n$. Now I still use the Lagrange multiplier $\lambda =-n/K$ (right?)and $$f(x)=\sum_{i=1}^n \log x_i + \lambda \left( \sum_{i=1}^nx_i-K \right)$$
Now
$$\frac{\partial f}{\partial x_i}=\frac{1}{x_i}-\frac{n}{K}$$
For $i=1,...,q$, $\frac{1}{x_i}-\frac{n}{K}>0$, so $f$ is larger when $x_i$ is larger. For $i=q+1,...,n$, $\frac{1}{x_i}-\frac{n}{K}<0$, so $f$ is larger when $x_i$ is smaller.
Now I think I can say $\Pi_{i=1}^nx_i$ is maximized when $x_i$ approaches the mean value as close as possible. However, I am still not clear on some questions.
a) Am I right to use Lagrange multiplier in the Case 2?
b) if $x_i$ are upper or lower bounded by $\alpha _i$ and $\beta _i$, can we say $\Pi_{i=1}^nx_i$ is maximized when these bounded are achieved? When $\sum \alpha _i+\sum \beta _i=K$, I think so.
