Example 5 Find the maximum and minimum values of the function
$$
f(x)=|x+2|+|x-1|+|2 x-1|-|5 x-2|
$$

and the values of $x$ at which these values are attained.
【Analysis】By factoring out the coefficient of the independent variable inside the absolute value symbol and arranging them in ascending order of the zero points of the absolute value expression, we have
$$
\begin{aligned}
f(x)= & |x+2|-5\left|x-\frac{2}{5}\right|+2\left|x-\frac{1}{2}\right|+ \\
& |x-1| .
\end{aligned}
$$

If we remove the absolute value symbols by classifying and discussing, the function can be transformed into a piecewise function, and each segment is a linear function (a linear function or a constant function).

Obviously, the graph of the function is a continuous broken line, and the sides of the broken line are rays, the middle part is a line segment, and the breakpoints are the points corresponding to the zero points of the absolute value
$$
\begin{array}{l}
A_{1}(-2, f(-2)), A_{2}\left(\frac{2}{5}, f\left(\frac{2}{5}\right)\right), \\
A_{3}\left(\frac{1}{2}, f\left(\frac{1}{2}\right)\right), A_{4}(1, f(1)) .
\end{array}
$$

Since the sum of the coefficients outside the absolute value symbols is less than 0, the rays on both sides of the broken line graph extend infinitely downward. Therefore, the function has no minimum value, but it has a maximum value, and the maximum value is the y-coordinate of the highest point among the breakpoints, i.e.,
$$
\begin{array}{l}
f(x)_{\max }=\max \left\{f(-2), f\left(\frac{2}{5}\right), f\left(\frac{1}{2}\right), f(1)\right\} . \\
\text { By } f(-2)=-4, f\left(\frac{2}{5}\right)=\frac{18}{5}, \\
f\left(\frac{1}{2}\right)=\frac{5}{2}, f(1)=1 \text {, }
\end{array}
$$

we know that the function $f(x)$ achieves its maximum value $\frac{18}{5}$ if and only if $x=\frac{2}{5}$.
Following this method, it is not difficult to obtain a more general conclusion.
Conclusion 2 Let the function $f(x)=\sum_{i=1}^{n} k_{i}\left|x-a_{i}\right|$, where $k_{i} 、 a_{i} \in \mathbf{R}, i=1,2, \cdots, n, x \in \mathbf{R}$. Then
(1) When $\sum_{i=1}^{n} k_{i}>0$, the graph of $f(x)$ is a continuous broken line, with the rays on both sides extending infinitely upward, the function $f(x)$ has a minimum value, but no maximum value, and the minimum value of $f(x)$ is
$$
\min \left\{f\left(a_{1}\right), f\left(a_{2}\right), \cdots, f\left(a_{n}\right)\right\} ;
$$
(2) When $\sum_{i=1}^{n} k_{i}=0$, the graph of $f(x)$ is a continuous broken line, with the rays on both sides extending infinitely along the $x$-axis, the function $f(x)$ has both a maximum value and a minimum value, and the maximum value of $f(x)$ is
$$
\max \left\{f\left(a_{1}\right), f\left(a_{2}\right), \cdots, f\left(a_{n}\right)\right\},
$$
the minimum value of $f(x)$ is
$$
\min \left\{f\left(a_{1}\right), f\left(a_{2}\right), \cdots, f\left(a_{n}\right)\right\} ;
$$
(3) When $\sum_{i=1}^{n} k_{i}<0$, the graph of $f(x)$ is a continuous broken line, with the rays on both sides extending infinitely downward, the function $f(x)$ has a maximum value, but no minimum value, and the maximum value of $f(x)$ is
$$
\max \left\{f\left(a_{1}\right), f\left(a_{2}\right), \cdots, f\left(a_{n}\right)\right\} .
$$