Prove that $ \int_0^1|f(x)-x|dx\leq 1/4 $ if $ f $ is increasing on $ [0,1] $, $ 0\leq f(x)\leq 1 $ and $ \int_0^1(f(x)-x)dx=0 $. 
Let $ f $ be an increasing function on $ [0,1] $ such that $ 0\leq f(x)\leq 1 $ and $ \int_0^1(f(x)-x)dx=0 $. Show that
\begin{align}
\int_0^1|f(x)-x|dx\leq 1/4.
\end{align}

Here is my try. I find that the equality is satisfied for $ f\equiv 1/2 $. Moreover, I want to use the Poincaré inequality but I cannot bound $ \int_0^1|f'(x)-1|dx $ by $ 1/4 $. Can you give me some references or hints?
 A: Step 1. (Proof under extra assumptions) Assume that

*

*$f : [0, 1] \to [0, 1]$ is continuous and non-decreasing;

*$\int_{0}^{1} (f(x) - x) \, \mathrm{d}x = 0$;

*$f(0) = 0$, and $f(1) = 1$.

Then the set $U_+ = \{ x \in [0, 1] : f(x) > x \}$ is open, hence it is written as the union of at most countably many disjoint open intervals $(a_i, b_i)$, $i = 1, 2, \ldots $ Also, the continuity of $f$ forces that $f(b_i) = b_i$. So,
\begin{align*}
I_+ &:= \int_{U_+} |f(x) - x| \, \mathrm{d}x
= \sum_{i} \int_{(a_i, b_i)} (f(x) - x) \, \mathrm{d}x \\
&\leq \sum_{i} \int_{(a_i, b_i)} (b_i - x) \, \mathrm{d}x
= \sum_{i} \frac{(b_i - a_i)^2}{2} \\
&\leq \frac{1}{2}\biggl( \sum_{i} (b_i - a_i) \biggr)^2
= \frac{1}{2} \operatorname{Leb}(U_+)^2.
\end{align*}
A similar argument shows that, for $U_- = \{ x \in [0, 1] : f(x) < x \}$ we have
\begin{align*}
I_- := \int_{U_-} |f(x) - x| \, \mathrm{d}x 
\leq \frac{1}{2} \operatorname{Leb}(U_-)^2.
\end{align*}
Moreover, from $\int_{0}^{1} (f(x) - x) \, \mathrm{d}x = 0$ we get $I_+ = I_-$. Therefore, together with the observations$ \int_{0}^{1} |f(x) - x| \, \mathrm{d}x = 2I_+ = 2I_-$ and $\operatorname{Leb}(U_+) + \operatorname{Leb}(U_-) \leq 1$, we conclude that
$$ \int_{0}^{1} |f(x) - x| \, \mathrm{d}x \leq \min\{ \operatorname{Leb}(U_+), \operatorname{Leb}(U_-) \}^2 \leq \frac{1}{4}. $$
These inequalities have a nice interpretation in terms of areas:

Step 2. (General case by approximation) Now suppose $f : [0, 1] \to [0, 1]$ is non-decreasing and satisfies $\int_{0}^{1} (f(x) - x) \, \mathrm{d}x = 0$. Then it is not hard to find a sequence $f_n(x)$ satisfying the conditions in Step 1 and $f_n(x) \to f(x)$ for almost every $x$. So, by the dominated convergence theorem,
$$ \int_{0}^{1} |f(x) - x| \, \mathrm{d}x
= \lim_{n\to\infty} \int_{0}^{1} |f_n(x) - x| \, \mathrm{d}x
\leq \frac{1}{4}. $$
