4. The largest solution and the smallest solution of the equation $\left[\frac{x}{2}\right]+\left[\frac{x}{3}\right]+\left[\frac{x}{7}\right]=x$ sum to $(\quad)$ (where, $[x]$ denotes the greatest integer not exceeding $x$, the same applies below).
(A) 85
(B) -85
(C) 42
(D) -42
4.B.
Let $x=42 p+q(p, q$ be integers, $0 \leqslant q \leqslant 41)$.
Substituting $x$ into the original equation, we get
$$
p=\left[\frac{q}{2}\right]+\left[\frac{q}{3}\right]+\left[\frac{q}{7}\right]-q \text {. }
$$

For each different $q$, a unique ordered pair $(p, q)$ is determined, and thus, $x$ is also unique. To compare the sizes of $x$, we should first compare the sizes of $p$, and if $p$ is equal, then compare the sizes of $q$.
$$
\begin{array}{l}
\text { Since } p=\left[\frac{q}{2}\right]+\left[\frac{q}{3}\right]+\left[\frac{q}{7}\right]-q \\
\leqslant \frac{q}{2}+\frac{q}{3}+\frac{q}{7}-q=-\frac{q}{42} \leqslant 0,
\end{array}
$$

Therefore, the maximum value of $p$ is only achieved when $q=0$, and the maximum value is 0.
Thus, the largest solution for $x$ is 0.
$$
\begin{array}{l}
\text { Also, } p=\left[\frac{q}{2}\right]+\left[\frac{q}{3}\right]+\left[\frac{q}{7}\right]-q \\
\geqslant \frac{q-1}{2}+\frac{q-2}{3}+\frac{q-6}{7}-q=-\frac{q+85}{42} \\
\geqslant-3,
\end{array}
$$

Therefore, $p \geqslant-3$.
When and only when $q=41$, $p=-3$.
Thus, the smallest solution for $x$ is -85.
In summary, the sum of the largest and smallest solutions is
-85.