Largest distance in an unusual metric Let $\bf x$ and $\bf y$ be two vectors in $n$-dimensional real space in the first orthant, i.e. all $x_i \ge0$ and  $y_i \ge0$, and with the condition $\sum_{i=1}^n x_i =  \sum_{i=1}^n y_i = n$.  Find a tight upper limit $Q$ in
$$
\sum_{i=1}^n \log ((x_i-y_i)^2) \le Q
$$
and give the vectors $\bf x$ and $\bf y$ where this limit is reached. For $Q$ I conjecture a linear behavior in $n$ (see below).
To get an idea what's going on, consider the same question without the logarithms, i.e. find $
\sum_{i=1}^n (x_i-y_i)^2 \le M
$. What we need to consider is indeed the Euclidean distance  $(\bf x -y)^2$ of two vectors. The condition $\sum_{i=1}^n x_i =  \sum_{i=1}^n y_i = n$ defines a hyperplane which cuts out of the first orthant  a triangle for $n=3$ and for general $n$, produces a triangular hyperpyramid. The Euclidean distance of two points in a hyperpyramid is largest for two corners, i.e. in  this case   $
\sum_{i=1}^n (x_i-y_i)^2 \le (n-0)^2 + (0-n)^2 + (0-0)^2 + \cdots = 2 n^2
$. The vectors $\bf x$ and $\bf y$ where this limit is reached are any pair of corners.
Now obviously, this doesn't translate into the original question, since for any pair of corners  we would have  $
\sum_{i=1}^n \log (x_i-y_i)^2 =  \log(n-0)^2 + \log (0-n)^2 + \log(0-0)^2 + \cdots \to - \infty
$. 
Instead, for $Q$ I conjecture a linear behavior in $n$. This behavior is observed in the following case (and I suppose the general case will also be linear in $n$):  Let all $y_i=1$. Choose some $a$ with $1<a<n$ and $x_1=\cdots=x_k=a$ for $k=n/a$, and all other $x_i=0$. We leave aside at this point whether $n/a$ gives an integer $k$. Then we have $
\sum_{i=1}^n \log ((x_i-y_i)^2) = 2 n/a \log(a-1)$. Now we can maximize this expression w.r.t. $a$, since the maximum of $1/a \log(a-1)$ occurs at $a=e$, so in the current setting $
\sum_{i=1}^n \log ((x_i-y_i)^2) \le 2 n/e \log(e-1) \simeq 0.4 n$. 
 A: We have
$$
f(\mathbf x, \mathbf y) = \sum_{i=1}^n \log ((x_i-y_i)^2) = 2 \log \prod_{i=1}^n \lvert x_i - y_i \lvert
$$
and 
$$
\prod_{i=1}^n \lvert x_i - y_i \lvert \le \left( \frac{\sum_{i=1}^n \lvert x_i - y_i \lvert }{n}\right)^n
\le \left( \frac{\sum_{i=1}^n (x_i + y_i)  }{n}\right)^n = 2^n
$$
so that $f(\mathbf x, \mathbf y) \le 2 n \log 2$ is an upper bound. For even $n$ the bound is sharp and attained for
$$
 \mathbf x = (2, \ldots, 2, 0, \ldots 0) \\
 \mathbf y = (0, \ldots, 0, 2, \ldots 2) \\
$$
For odd $n$ the bound is almost sharp. For
$$
 \mathbf x = (\frac{2n}{n+1}, \ldots, \frac{2n}{n+1}, 0, \ldots 0) \\
 \mathbf y = (0, \ldots, 0, \frac{2n}{n-1}, \ldots , \frac{2n}{n-1}) \\
$$
we get
$$
 f(\mathbf x, \mathbf y) = 2 \left( \frac{n+1}{2} \log \frac{2n}{n+1} + \frac{n-1}{2} \log \frac{2n}{n-1}\right) \\
= 2 n \log 2 + (n+1) \log \frac{n}{n+1} + (n-1)\log \frac{n}{n-1} \, .
$$
Using the estimate $\log x \ge \frac{x-1}{x}$ it follows that
$$
 f(\mathbf x, \mathbf y) \ge 2 n \log 2 - \frac 2n \, .
$$
So in any case, the maximal possible value $Q_n$ satisfies
$$
 2 n \log 2 - \frac 2n \le Q_n \le  2 n \log 2 
$$
which confirms the conjectured linear growth with $n$.
