How to show that $g$ attains maximum at $0$ or $1$ Suppose $f:[0,1]\to\mathbb{R}$ is continuous，define 
$$g:[0,1]\to\mathbb{R},\quad g(x):=\int_0^1|f(t)-x|dt$$
Show that $g$ attains maximum at $0$ or $1$.
I don't know how to approach, any hints?
 A: Essentially we need to use convexity of g(x). For any $x,t\in(0,1)$, we have 
$$
|f(t)-x|\le x|f(t)-1|+(1-x)|f(t)|
$$
Integrate on both sides form $0$ to $1$ with respect to $t$, we obtain
$$
g(x)\le x\cdot g(1)+(1-x)\cdot g(0)
$$.
Now suppose the contrary, if there exists $x_0\in(0,1)$ such that $g(x_0)>g(0)$ and $g(x_0)>g(1)$, then 
$$
 x_0\cdot g(1)+(1-x_0)\cdot g(0)<g(x_0)\le x_0\cdot g(1)+(1-x_0)\cdot g(0)
$$
which is a contradiction.
A: Show that $g$ is convex.  This follows since $x \mapsto |x-c|$ is convex.
Now to show is that $g$ is non-constant.  There are two possibilities.


*

*Either $f([0,1]) \subset (-\infty, 0]$, or $f([0,1]) \subset [1,\infty)$.  And in either of these cases, $g$ is linear with slope $-1$ or $1$.

*Or, since $f$ is continuous, there exists $\epsilon,\delta>0$, $t_0\in (\epsilon,1-\epsilon)$ such that $f([t_0-\epsilon,t_0+\epsilon]) \subset [\delta,1-\delta]$.  Then for $t \in [t_0-\epsilon,t_0+\epsilon]$ we have that $$\tfrac12|f(t)| + \tfrac12|f(t)-1| = \tfrac12 f(t) + \tfrac12(1-f(t)) = \tfrac12 \ge |f(t)-\tfrac12| + \delta $$
Since for all $t \in [0,1]$ we also have
$$\tfrac12|f(t)| + \tfrac12|f(t)-1|  \ge |f(t)-\tfrac12|  $$
then integrating we get
$$ \tfrac12 g(0) + \tfrac12 g(1) \ge g(\tfrac12) + 2\epsilon\delta ,$$
and hence $g$ is non-constant.


Since $g$ is convex and non-constant, it cannot attain its maximum on $(0,1)$.
