5. A retired worker receives a pension each year, the amount of which is proportional to the square of the number of years he worked. If he had worked $a$ more years, his pension would be $p$ yuan more than it is now; if he had worked $b$ more years $(a \neq b, a 、 b$ $>0$ ), his pension would be $q$ yuan more than it is now. Then, his current pension is ( ) yuan.
(A) $\frac{p^{2}-q^{2}}{2(a-b)}$
(B) $\frac{(p-q)^{2}}{2 \sqrt{a b}}$
(C) $\frac{a p^{2}-b q^{2}}{2(a p-b q)}$
(D) $\frac{a q^{2}-b p^{2}}{2(b p-a q)}$
5. (D).

Let $x$ be the pension, $y$ be the years of service, and $k$ be the proportionality constant. From the given information, we have
$$
\begin{array}{l}
x=k \sqrt{y}, x+p=k \sqrt{y+a}, \\
x+q=k \sqrt{y+b} .
\end{array}
$$

Thus, $x^{2}=k^{2} y,(x+p)^{2}=k^{2}(y+a)$,
$$
(x+q)^{2}=k^{2}(y+b) .
$$

Substituting $x^{2}=k^{2} y$ into the last two equations, we get
$$
\begin{array}{l}
p^{2}+2 p x=k^{2} a, q^{2}+2 q x=k^{2} b . \\
\text { Hence } \frac{2}{2 q x+q^{2}}=\frac{a}{b} \Rightarrow x=\frac{a q^{2}-b p^{2}}{2(b p-a q)} .
\end{array}
$$

Note: This implies $b p \neq a q$. Otherwise, if $b p=a q$, then
$$
2 p q x+p^{2} q=k^{2} a q=k^{2} b p=q^{2} p+2 p q x \Rightarrow p=q \Rightarrow a
$$
$=b$, which is a contradiction. Therefore, $b p-a q \neq 0$ always holds.