Inequality originated from order statistics The following question is given in V.K Rohatgi problem 7.2.4.
Let $x_1,x_2,...,x_n$ be real numbers, and let $x_{(n)} = \max(x_1,x_2,...,x_n) $ for $n\geq 2$, and $x_{(1)} = \min(x_1,x_2,...,x_n)$. Show that for any set of real numbers $a_1,a_2,...,a_n$ such that $\sum_{i=1}^n a_i = 0$, the following inequality holds: 
       $$\left|\sum_{i=1}^n a_i.x_i\right| \leq \frac{1}{2}(x_{(n)} - x_{(1)})\sum_{i=1}^n |a_i|$$
 A: We assume without loss of generality that all the $a_i$ are non-zero.
Note that $a_i+|a_i|=0$ if $a_i< 0$ and $a_i+|a_i|=2a_i$ if $a_i> 0$.
Similarly, $a_i-|a_i|=0$ if $a_i> 0$ and $a_i-|a_i|=2a_i$ if $a_i< 0$.
Therefore, $\sum_i(|a_i|+a_i)=2\sum_{i, a_i> 0} a_i$ and $\sum_i(|a_i|-a_i)=-2\sum_{i, a_i< 0} a_i$. Using the hypothesis $\sum_i a_i = 0$, we get $$\sum_i|a_i| = 2\sum_{i, a_i> 0} a_i=-2\sum_{i, a_i< 0} a_i$$

If $a_i<0$, $a_ix_{(n)}\leq a_ix_i\leq a_ix_{(1)}$, hence $$x_{(n)}\sum_{i, a_i< 0} a_i \leq \sum_{i, a_i< 0}a_ix_i \leq x_{(1)}\sum_{i, a_i< 0} a_i  $$
Similarly, $$x_{(1)}\sum_{i, a_i> 0} a_i \leq \sum_{i, a_i> 0}a_ix_i \leq x_{(n)}\sum_{i, a_i> 0} a_i  $$
Summing these last two inequalities, $$x_{(1)}\sum_{i, a_i> 0} a_i + x_{(n)}\sum_{i, a_i< 0} a_i\leq \sum_{i}a_ix_i \leq x_{(1)}\sum_{i, a_i< 0} a_i + x_{(n)}\sum_{i, a_i> 0} a_i$$
But $ \displaystyle x_{(1)}\sum_{i, a_i< 0} a_i + x_{(n)}\sum_{i, a_i> 0} a_i = x_{(1)}\left(-\frac{1}2 \sum_i |a_i| \right)+x_{(n)}\left(\frac{1}2 \sum_i |a_i| \right) = \frac {x_{(n)}-x_{(1)}}2 \sum_i |a_i|$
Similarly, $\displaystyle x_{(1)}\sum_{i, a_i> 0} a_i + x_{(n)}\sum_{i, a_i< 0} a_i = -\frac {x_{(n)}-x_{(1)}}2 \sum_i |a_i|$
Hence $$-\frac {x_{(n)}-x_{(1)}}2 \sum_i |a_i|\leq \sum_{i}a_ix_i \leq \frac {x_{(n)}-x_{(1)}}2 \sum_i |a_i|$$
Lastly, $$\left|\sum_{i} a_ix_i\right| \leq \frac{x_{(n)} - x_{(1)}}{2}\sum_{i} |a_i|$$
