5. Let $a_{1}, a_{2}, \cdots, a_{n}$ be given non-zero real numbers, and $r_{1}, r_{2}, \cdots, r_{n}$ be real numbers. The inequality $\sum_{i=1}^{n} r_{i}\left(x_{i}-a_{i}\right) \leqslant \sqrt{\sum_{i=1}^{n} x_{i}^{2}}-\sqrt{\sum_{i=1}^{n} a_{i}^{2}}$ holds for any real numbers $x_{1}, x_{2}, \cdots, x_{n}$. Find the values of $r_{1}, r_{2}, \cdots, r_{n}$. (3rd CMO Problem)
5. Let $x_{i}=0(i=1,2, \cdots, n)$, then $\sum_{i=1}^{n} r_{i} a_{i} \geqslant \sqrt{\sum_{i=1}^{n} a_{i}^{2}}$.

Let $x_{i}=2 a_{i}(i=1,2, \cdots, n)$, then $\sum_{i=1}^{n} r_{i} a_{i} \geqslant \sqrt{\sum_{i=1}^{n} a_{i}^{2}}$.
Therefore,
$$\sum_{i=1}^{n} r_{i} a_{i}=\sqrt{\sum_{i=1}^{n} a_{i}^{2}}$$

Let $x_{i}=r_{i}(i=1,2, \cdots, n)$, then
$$\sum_{i=1}^{n} r_{i}^{2}-\sum_{i=1}^{n} r_{i} a_{i} \leqslant \sqrt{\sum_{i=1}^{n} r_{i}^{2}}-\sqrt{\sum_{i=1}^{n} a_{i}^{2}}$$

From (1) and (2), we get $\sum_{i=1}^{n} r_{i}^{2} \leqslant \sqrt{\sum_{i=1}^{n} r_{i}^{2}}$, so
$$\sum_{i=1}^{n} r_{i}^{2} \leqslant 1$$

By the Cauchy-Schwarz inequality, we have
$$\sum_{i=1}^{n} r_{i} a_{i} \leqslant \sqrt{\sum_{i=1}^{n} r_{i}^{2}} \sqrt{\sum_{i=1}^{n} a_{i}^{2}}$$

From (1) and (4), we know
$$\sum_{i=1}^{n} r_{i}^{2} \geqslant 1$$

From (3) and (5), we know
$$\sum_{i=1}^{n} r_{i}^{2}=1$$

The condition for equality in (4) is $\frac{r_{1}}{a_{1}}=\frac{r_{2}}{a_{2}}=\cdots=\frac{r_{n}}{a_{n}}$. Let $\lambda=\frac{r_{k}}{a_{k}}$, then $r_{k}=\lambda a_{k}(k=1,2, \cdots, n)$, substituting into (1) gives $\lambda=\frac{1}{\sqrt{\sum_{i=1}^{n} a_{i}^{2}}}$, hence $r_{k}=\frac{a_{k}}{\sqrt{\sum_{i=1}^{n} a_{i}^{2}}}(k=1,2, \cdots, n)$.