Let $b>a>0$ and $M>0$ be fixed. Let $F$ be the set of all functions $f:[a,b]\to[-M,M]$ such that $$\int_a^bf(x)\,\mathrm dx=0.$$Find$$\max_{f\in F}\int_a^b\frac{f(x)}x\,\mathrm dx.$$
I tried to use the CBS inequality for integrals for the functions $(f(x))^2$ and $\dfrac{1}{x^2}$, but when I tried to find the equality case, the function $f(x)=\dfrac{k}{x}$ I got did not satisfy $\displaystyle\int_a^bf(x)\,\mathrm dx=0$. So the maximum must be lower than what I found. But I do not know anything about the continuity of $f$ and I don't know how to continue.
$\def\d{\mathrm{d}}\def\peq{\mathrel{\phantom{=}}{}}$For any fixed $f \in F$, define$$ g(x) = \int_a^x f(u) \,\d u, \quad \forall x \in [a, b] $$ then $g' = f$ almost everywhere and $g(a) = g(b) = 0$. Since $|f(x)| \leqslant M$, then for any $a \leqslant x \leqslant \dfrac{a + b}{2}$,$$ g(x) = \int_a^x f(u) \,\d u \leqslant M (x - a), $$ and for any $\dfrac{a + b}{2} < x \leqslant b$,$$ g(x) = g(b) - \int_x^b f(u) \,\d u \leqslant M(b - x). $$ Therefore by integration by parts,$$ \int_a^b \frac{f(x)}{x} \,\d x = \int_a^b \frac{g'(x)}{x} \,\d x = \left. \frac{g(x)}{x} \right|_a^b + \int_a^b \frac{g(x)}{x^2} \,\d x = \int_a^b \frac{g(x)}{x^2} \,\d x\\ = \int_a^{\tfrac{a + b}{2}} \frac{g(x)}{x^2} \,\d x + \int_{\tfrac{a + b}{2}}^b \frac{g(x)}{x^2} \,\d x \leqslant M \int_a^{\tfrac{a + b}{2}} \frac{x - a}{x^2} \,\d x + M \int_{\tfrac{a + b}{2}}^b \frac{b - x}{x^2} \,\d x = M \ln\frac{(a + b)^2}{4ab}. $$
Note that the above inequality becomes equality for$$ f(x) = \begin{cases}M;& a \leqslant x \leqslant \dfrac{a + b}{2}\\-M;& \dfrac{a + b}{2} < x \leqslant b\end{cases}, $$ thus the maximum is $M \ln\dfrac{(a + b)^2}{4ab}$.