Inequality with absolute values and finding largest value of y Find when does the equality hold and the largest value of y for which for all x: $|x-a_1|+\ldots+|x-a_n|\ge y$
Given that $a_1<\ldots<a_n$, I was thinking to consider the value $x=(a_1+a_n)/2$
 A: Each term $|x-a_i|$ looks like  $V$ when graphed in $x$. The total sum of these gives you a convex, parabolic looking object (see here for example). So let $f(x):=|x-a_1|+...|x-a_n|$
The answer is that the minimum always occurs at the median of the $a_i$, or more generally at any point between the median and next closest $a_i$. To see this, first suppose $n$ is even. Then when $x=M$ is the median, it satisfies $a_1<...<a_n<M<a_{n+1}...<a_{2n}$. In this case, $|x-a_i|=x-a_i$ for $i\leq n$ and $|x-a_i|=a_i-x$ when $i>n$, giving $S=a_{n+1}+\cdots+a_{2n}-a_1-\cdots-a_n$. 
To show this is the minimum, you can use the fact that $f(x)$ is convex. Then it suffices to show that for $a_{n+2}>x>a_{n+1}$ and for $a_{n-1}<x<a_n$, you get a larger $f(x)$. This is easy because $a_{n+1}>a_n$, so if $x>a_{n+1}$, you'll get a sign-reversal so that the above sum becomes $S-a_{n+1}+2a_{n+1}-a_{n}=S+a_{n+1}-a_{n}>S$. Similarly if $a_{n-1}<x<a_{n}$, then you get $S-a_n+2a_n-a_{n-1}=S+a_{n}-a_{n-1}>S$. 
For $2n+1$ odd, set $x=a_n$ and repeat the above argument in a similar fashion.
A: Let set $f(x)=\sum\limits_{i=1}^{n}|x-a_i|$ $\DeclareMathOperator{\sgn}{sgn}$
We have $f'(x)\overset{a.e}{=}\sum\limits_{i=1}^{n}\sgn(x-a_i)=\#\{i\ \mid x>a_i\}-\#\{i\ \mid x<a_i\}$ 
Note: $f'$ is not defined at the $a_i$, but this is not important since $f$ is continuous, we are only interested in its variations.
It is possible to choose $x$ such that there is either an equal number of indices in each set (in which case $f'(x)=0$) or the difference is one (in which case $f'(x)=\pm 1$), depending whether $n$ is odd or even.
For $n=2p$ we have this variation array
$\begin{array}{c|cccccc}
x & -\infty && a_p && a_{p+1} && +\infty\\\hline
f' && - &|& 0 &|& + &\\\hline
f && \searrow &|& \to &|& \nearrow&\\
\end{array}$ 
Thus $f$ has a minimum on $]a_p,a_{p+1}[$ and by continuity on $[a_p,a_{p+1}]$
For $n=2p+1$ we have this variation array
$\begin{array}{c|cccccc}
x & -\infty && a_{p+1} && +\infty\\\hline
f' && - &|& + & \\\hline
f && \searrow &|& \nearrow&\\
\end{array}$ 
Thus since $f$ is continuous it has a minimum in $a_{p+1}$.
In any case the minimum is reached in $a_{p+1}$.
$$y_{max}=\min\limits_{x\in\mathbb R} f(x)=f(a_{\lfloor\frac n2\rfloor+1})$$
