4. For each $x$, the function $y$ is the maximum of the functions
$$
y_{1}=2 x, y_{2}=x+3, y_{3}=-x+3
$$

Then the minimum value of the function $y$ is ( ).
(A)2
(B) 3
(C) 5
(D) 6
4. B.

As shown in Figure 4, the intersection point of the graphs of functions $y_{1}$ and $y_{2}$ is $(3,6)$, and the intersection point of the graphs of functions $y_{2}$ and $y_{3}$ is $(0,3)$.
From the problem and the graph, we have
$$
y=\left\{\begin{array}{ll}
-x+3, & x<0 ; \\
x+3, & 0 \leqslant x<3 \\
2 x, & x \geqslant 3 .
\end{array}\right.
$$

Therefore, the minimum value of $y$ is 3.