5. Given an integer $n(n \geqslant 4)$, for any non-zero real numbers $a_{1}, a_{2}, \cdots, a_{n}, b_{1}, b_{2}, \cdots, b_{n}$ satisfying
$$
a_{1}+a_{2}+\cdots+a_{n}=b_{1}+b_{2}+\cdots+b_{n}>0
$$

find the maximum value of
$$
\frac{\sum_{i=1}^{n} a_{i}\left(a_{i}+b_{i}\right)}{\sum_{i=1}^{n} b_{i}\left(a_{i}+b_{i}\right)}
$$
5. The maximum value sought is $n-1$.

By homogeneity, we may assume
$$
\sum_{i=1}^{n} a_{i}=\sum_{i=1}^{n} b_{i}=1 \text {. }
$$

First, consider
$$
\begin{array}{l}
a_{1}=1, a_{2}=a_{3}=\cdots=a_{n}=0, \\
b_{1}=0, b_{2}=b_{3}=\cdots=b_{n}=\frac{1}{n-1}
\end{array}
$$

In this case, we have
$$
\begin{array}{l}
\sum_{i=1}^{n} a_{i}\left(a_{i}+b_{i}\right)=1, \\
\sum_{i=1}^{n} b_{i}\left(a_{i}+b_{i}\right)=\frac{1}{n-1} \text {. } \\
\text { Hence } \frac{\sum_{i=1}^{n} a_{i}\left(a_{i}+b_{i}\right)}{\sum_{i=1}^{n} b_{i}\left(a_{i}+b_{i}\right)}=n-1 \text {. } \\
\end{array}
$$

Next, we prove that for any $a_{1}, a_{2}, \cdots, a_{n}, b_{1}, b_{2}, \cdots, b_{n}$ satisfying
$$
\sum_{i=1}^{n} a_{i}=\sum_{i=1}^{n} b_{i}=1
$$

we have
$$
\frac{\sum_{i=1}^{n} a_{i}\left(a_{i}+b_{i}\right)}{\sum_{i=1}^{n} b_{i}\left(a_{i}+b_{i}\right)} \leqslant n-1 .
$$

Since the denominator is positive, the above inequality is equivalent to
$$
\sum_{i=1}^{n} a_{i}\left(a_{i}+b_{i}\right) \leqslant(n-1) \sum_{i=1}^{n} b_{i}\left(a_{i}+b_{i}\right) \text {, }
$$

which is
$$
(n-1) \sum_{i=1}^{n} b_{i}^{2}+(n-2) \sum_{i=1}^{n} a_{i} b_{i} \geqslant \sum_{i=1}^{n} a_{i}^{2}.
$$
By symmetry, we may assume $b_{1}$ is the smallest among $b_{1}, b_{2}, \cdots, b_{n}$. Then
$$
\begin{array}{l}
(n-1) \sum_{i=1}^{n} b_{i}^{2}+(n-2) \sum_{i=1}^{n} a_{i} b_{i} \\
\geqslant(n-1) b_{1}^{2}+(n-1) \sum_{i=2}^{n} b_{i}^{2}+(n-2) \sum_{i=1}^{n} a_{i} b_{1} \\
\geqslant(n-1) b_{1}^{2}+\left(\sum_{i=2}^{n} b_{i}\right)^{2}+(n-2) b_{1} \\
=(n-1) b_{1}^{2}+\left(1-b_{1}\right)^{2}+(n-2) b_{1} \\
=n b_{1}^{2}+(n-4) b_{1}+1 \\
\geqslant 1=\sum_{i=1}^{n} a_{i} \geqslant \sum_{i=1}^{n} a_{i}^{2} .
\end{array}
$$