Let $f,g$ be Riemann integrable functions in $[a,b]$ such that $g$ is non-negative. Let $m,M$ be real numbers such that $$m\leq\inf\{f(x):x\in[a,b]\},$$ $$\sup\{f(x):x\in[a,b]\}\leq M.$$ Show that there is a number $c\in[a,b]$ such that $$\int_{a}^{b}f(x)g(x)dx=m\int_{a}^{c}g(x)dx+M\int_{c}^{b}g(x)dx.$$
It's clear that $f$ is bounded $(m\leq f(x)\leq M)$ in $[a,b]$. I know that if $h,m$ are continuous functions in $[a,b]$ and $m\geq 0.$ Then there exists a number $c\in[a,b]$ such that $$\int_{a}^{b}h(x)m(x)dx=h(c)\int_{a}^{b}m(x)dx.$$
I think this result would be useful, but I'm stuck since the hypothesis of the exercise are a little but different from the hypothesis of the result. Any advice? Thanks!
Define
$$ h(t) := m\int_{a}^{t}g(x)dx+M\int_{t}^{b}g(x)\mathrm{d}x $$ for all $t \in [a, b]$, then h is continuous and satisfies
$$ h(b) \leq \int_{a}^{b}f(x)g(x)\mathrm{d}x \leq h(a), $$
so by the IVT there must be a $c\in[a,b]$ such that
$$ \int_{a}^{b}f(x)g(x)\mathrm{d}x = h(c) = m\int_{a}^{c}g(x)dx+M\int_{c}^{b}g(x)\mathrm{d}x. $$