Let
$$g(a)=\int_{0}^{\pi/2} |\sin 2x-a\cos x|dx,\quad a\in[0,1].$$
If $L$ and $M$ are the minimum and maximum values of $g(a)$ for all $a\in [0,1]$. Find the value of $L+M$.
The first thing I tried was trying to graph the function. Taking $\cos x$ common from the integrand and out of the modulus as the integral goes from $0$ to $\pi /2$. But after that, how do you treat the parameter $a$ in the integrand? Differentiating $g(a)$ is difficult because there is no clear way of getting rid of the modulus. How do I go about this?
Hint. We have $a \in [0,1]$. Then one may write $$ \begin{align} g(a)&=\int_{0}^{\pi/2} |\sin 2x-a\cos x|dx \\\\&=2\int_{0}^{\pi/2}\left|\sin x-\frac{a}2\right|\cos x dx \\\\&=2\int_{0}^{1}\left|u-\frac{a}2\right|du \\\\&=2\int_{0}^{a/2}\left(\frac{a}2-u\right)du+2\int_{a/2}^{1}\left(u-\frac{a}2\right)du \end{align} $$ giving an explicit value of $g(a)$.