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...
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}$$