Proving $\int_0^1|f(x)|\,dx\leq\frac12$, for continuous $f$ with $|\max f(x)-\min f(x)|\leq 1$ and $\int_0^1f(x)dx=0$ 
Let $f$ be continuous on $[0,1]$, and $M=\max\limits_{x\in[0,1]}f(x)$, $m=\min\limits_{x\in[0,1]}f(x)$, $|M-m|\leqslant1$,$\int_0^1f(x)\mathrm{d}x=0$.Prove that
$$\int_0^1|f(x)|\mathrm{d}x\leqslant\frac{1}{2}$$

This is the homework assigned by the teacher. I have a little idea now:From Cauchy inequality,we have $$\int_0^1|f(x)|\mathrm{d}x\leqslant\left(\int_0^1f^2(x)\mathrm{d}x\right)^{\frac{1}{2}}.$$
Then, we can know from the question that$(f-m)(f-M)\leqslant0$,so
$$\int_0^1(f-m)(f-M)\mathrm{d}x=\int_0^1f^2(x)\mathrm{d}x+Mm\leqslant0\implies\int_0^1f^2(x)\mathrm{d}x\leqslant-Mm.$$
But I don't know what to do next...
 A: Let $I^+=\{x:f(x)>0\}$ and $I^-=\{x:f(x)<0\}$.  Assume that $\mu(I^+)=\delta$ where
$\mu$ stands for the Lebesgue measure of the set $I^+$. Then $\mu(I^-)\leq 1-\delta$.
Write
$$J:=\int_{0}^{1}|f(x)|dx=\int_{I^+}|f(x)|dx+\int_{I^-}|f(x)|dx$$
Now, since
$$\int_{I^+}|f(x)|dx\leq M \delta$$
and
$$\int_{I^-}|f(x)|dx\leq -m (1-\delta)$$
(becasue on $I^{-}$, $0\geq f\geq m$ $\implies$ $|f|=-f\leq -m$ )
then
$$J\leq M \delta-m (1-\delta).$$
But $|M-m|\leq 1$ which means $-m\leq 1-M$.
So
$$J\leq M \delta+(1-M) (1-\delta).$$
Minimize the function $H(M,\delta):=M \delta+(1-M) (1-\delta)$
in $\delta$ and $M$ on $[0,1]\times [0,1]$ (solve simultaneously the equations  $\frac{\partial H}{\partial M} =0,\; \frac{\partial H}{\partial \delta} =0$). You find that the minimize values are $M=\delta=\frac{1}{2}$. Hence
$$J\leq\frac{1}{2}$$
A: Call $\mathcal D^+ = \{x\in[0,1]: f(x)\geq 0\}$ and $\mathcal D^- = \{x\in[0,1]: f(x)<0\}$.
Suppose $M = 1-\varepsilon$, so that $-m\leq \varepsilon$.
Since
$$\int_0^1 f(x) dx = \int_{\mathcal D^+} f(x)dx + \int_{\mathcal D^-} f(x)dx=0$$
we must have
$$\int_{\mathcal D^+} f(x)dx =- \int_{\mathcal D^-} f(x)dx.$$
Also
$$\int_0^1 |f(x)| dx = 2\int_{\mathcal D^+} f(x)dx = -2\int_{\mathcal D^-} f(x)dx.$$
Suppose, by contradiction,
$$\int_{\mathcal D^+} f(x)dx >\frac14.$$
This implies
$$\frac14 < - \int_{\mathcal D^-} f(x)dx \leq\varepsilon \int_{\mathcal D^-}dx = \varepsilon \left(1-\int_{\mathcal D^+} dx\right).$$
Thus
$$\int_{\mathcal D^+} dx < 1-\frac1{4\varepsilon}.$$
Recalling that $f(x) \leq 1-\varepsilon$, we obtain
$$\frac14 < \int_{\mathcal D^+} f(x)dx \leq (1-\varepsilon)\left(1-\frac1{4\varepsilon}\right).$$
The last inequality is equivalent to
$$-\frac{(2\varepsilon-1)^2}{4\varepsilon}>0,$$
which is impossibile. The thesis follows.
A: Here is a simple probabilistic proof.
Consider the uniform distribution over $[0,1]$. By assumption
$E[f]=\int^1_0 f(x)\,dx =0$. If $\alpha \leq f\leq \beta$ almost surely on $[0,1]$, then $f\in L_2$ and
$$\begin{align}
\operatorname{Var}(f)=E[(f-E[f])^2]=\int^1_0(f(x)-E[f])^2\,dx\leq\frac{(\beta-\alpha)^2}{4}\tag{0}\label{0}
\end{align}$$
This follows from the fact that
$$\begin{align}
E[f]=\operatorname{arg}\min_{r\in\mathbb{R}}E\big[(f-r)^2\big]\tag{1}\label{1}\end{align}$$
By assumption, $\alpha=\min(f)$ and $\beta=\max(f)$ satisfy $\beta-\alpha\leq1$. An application of Cauchy-Schwartz yields
$$\|f\|_1\leq\|f\|_2=\sqrt{\operatorname{Var}(f)}\leq \frac{\beta-\alpha}{2}\leq \frac12$$.

A few details:
The well known equation \eqref{1} follows from
$$\begin{align}
E[(f-r)^2]&=E\Big[\big(f-E[f]+(E[f]-r)\big)^2\Big]\\
&=E\big[(f-E[f])^2\big]+\big(E[f]-r\big)^2\geq E\big[(f-E[f])^2\big]]
\end{align}$$
Inequality \eqref{0} then follows by taking $r=\frac{\alpha+\beta}{2}$, for this gives
$$\operatorname{Var}(f)\leq E[(f-r)^2]\leq\frac{(\beta-\alpha)^2}{4}$$
