Proving that a specific value is taken by a continuous function Let $f:x\longmapsto \dfrac 1n \displaystyle\sum_{k=1}^n |x - a_k|$ where $a_k$ are elements of the interval $[0,1]$ satisfying $a_1<a_2<\cdots <a_n$.
The question asks to prove that $f$ takes the value $\dfrac{a_1+a_n}{2}$
I tried using IVT by proving that $\dfrac{a_1+a_n}{2}$ lies between two known taken values of $f$ but I didn't achieve any  progress.
Some remarks : 
$$f(0) + f(1) = 1$$
$$f(a_1)=f(0)-a_1$$
$$f(a_n)=a_n-f(0)$$
Any hints would be appreciated.
 A: Note that $f(x)$ is convex, hence
$$
f\left(\frac{a_1 + a_n}{2}\right) \leq \frac{f(a_1) + f(a_n)}{2} = \frac{a_n - a_1}{2} \leq \frac{a_1 + a_n}{2}.
$$ 
Also, we have
$$
f(2) \geq 1 \geq \frac{a_1 + a_n}{2}.
$$
Then from IVT there exists $\xi \in \left[\frac{a_1 + a_n}{2}, 2\right]$ such that $f(\xi) = \frac{a_1 + a_n}{2}$.
A: Yes, IVT is the right tool here. Note that $f$ is continuous and convex function in $\mathbb{R}$ because it is a convex combination of the continuous and convex functions $x\to |x-a_k|$ for $k=1,2,\dots,n$. Hence, by your remarks,
$$f\left(\frac{a_1+a_n}{2}\right)\leq \frac{f(a_1)+f(a_n)}{2}=\frac{a_n-a_1}{2}\leq \frac{a_n+a_1}{2}.$$
Now, in order to apply IVT, it suffices to say that
$$\frac{a_n+a_1}{2}< \sup_{x\in \mathbb{R}} f(x)=+\infty.$$
P.S. It is not always true that
$$\frac{a_n+a_1}{2}\leq \max_{x\in [0,1]} f(x)=\max\{f(0),f(1)\}.$$
Take for example $a_1=1/3$, $a_2=1/2$, and $a_3=3/4$. It follows that the value $\frac{a_1+a_n}{2}$ could be attained by $f$ outside the interval $[0,1]$.
