4. Let $S_{n}$ be the sum of the first $n$ terms of the sequence $\left\{a_{n}\right\}$. If the inequality $a_{n}^{2}+\frac{S_{n}^{2}}{n^{2}} \geqslant \lambda a_{1}^{2}$ holds for any arithmetic sequence $\left\{a_{n}\right\}$ and any positive integer $n$, then the maximum value of $\lambda$ is
(A) 0
(B) $\frac{1}{5}$
(C) $\frac{1}{2}$
(D) 1
4. B.

Let the common difference of $\left\{a_{n}\right\}$ be $d$, then
$$
\begin{array}{l}
a_{n}^{2}+\frac{S_{n}^{2}}{n^{2}} \\
=\left[a_{1}+(n-1) d\right]^{2}+\frac{1}{n^{2}}\left[n a_{1}+\frac{n(n-1)}{2} d\right]^{2} \\
=2 a_{1}^{2}+3(n-1) a_{1} d+\frac{5}{4}(n-1)^{2} d^{2} \\
=\frac{1}{5} a_{1}^{2}+\left[\frac{3}{\sqrt{5}} a_{1}+\frac{\sqrt{5}}{2}(n-1) d\right]^{2} \geqslant \frac{1}{5} a_{1}^{2} .
\end{array}
$$

When $\frac{6 a_{1}}{5 d}$ is a negative integer, there exists a positive integer $n$ such that $\frac{3}{\sqrt{5}} a_{1}+\frac{\sqrt{5}}{2}(n-1) d=0$. Therefore, the required $\lambda_{\text {max }}=\frac{1}{5}$.