Solution (source code)

= Solution

The <extreme value theorem> ensures that $M$ is finite. Since $f(x)\leq|f(x)|\leq M$ and $g(x)\geq0$, multiplication preserves the inequality. Monotonicity of the <Riemann integral> gives \b[the required bound]
$$
\boxed{\int_0^1 fg\,dx\leq M\int_0^1g\,dx.}
$$
To prove the <weighted mean value theorem for integrals>, put $G=\int_0^1g\,dx$ and $I=\int_0^1fg\,dx$. If $G=0$, then $|I|\leq\int_0^1|f|g\,dx\leq MG=0$, so any $\alpha$ works. This includes $g\equiv0$.

If $G>0$, the <extreme value theorem> gives $m_0=\min f$ and $M_0=\max f$. Integrating $m_0g\leq fg\leq M_0g$ gives $m_0\leq I/G\leq M_0$. A <continuous function> on an interval takes every value between its minimum and maximum by the <intermediate value theorem>. Choose $\alpha$ with $f(\alpha)=I/G$. Consequently
$$
\boxed{\int_0^1fg\,dx=f(\alpha)\int_0^1g\,dx\quad\text{for some }\alpha\in[0,1].}
$$