5. Given that the quadratic function $f(x)$ has a maximum value of 5 when $x=m (m>0)$, the quadratic function $g(x)$ has a minimum value of -2, and $g(m)=$ 25, and $f(x)+g(x)=x^{2}+16 x+13$. Then the expression for $f(x)$ is $\qquad$ .
$$
\begin{array}{l}
\text { 5. }-2 x^{2}+4 x+3 . \\
\because f(x)+g(x)=x^{2}+16 x+13, \\
f(m)=5, g(m)=25, m>0, \\
\therefore m^{2}+16 m+13=30 .
\end{array}
$$

Solving, we get $m=1$.
Let $f(x)=a(x-1)^{2}+5=a x^{2}-2 a x+5+a$.
Then $g(x)=\left(x^{2}+16 x+13\right)-\left(a x^{2}-2 a x+5+a\right)$
$$
=(1-a) x^{2}+(2 a+16) x+8 \cdots a \text {. }
$$
$\because$ For the quadratic function, the minimum value of $g(x)$ is -2,
$$
\therefore \frac{4(1-a)(8-a)-(2 a+16)^{2}}{4(1-a)}=-2 \text {. }
$$

Solving, we get $a=-2$.
$$
\therefore f(x)=-2 x^{2}+4 x+3 \text {. }
$$