Example 5 There are three villages $A$, $B$, and $C$ forming a triangle (as shown in Figure 5). The ratio of the number of primary school students in villages $A$, $B$, and $C$ is $1: 2: 3$. A primary school needs to be established. Where should the school be located to minimize the total distance $S$ traveled by the students to school?
Solution: Let the primary school be located at point $P$, and the number of students from villages $A$, $B$, and $C$ be $a$, $2a$, and $3a$ respectively. Then,
$$
\begin{array}{l}
S=a P A+2 a P B+3 a P C \\
=a(P A+P C)+2 a(P B+P C) \\
\geqslant a A C+2 a B C .
\end{array}
$$

Equality holds if and only if $P=C$.
Therefore, setting the primary school in village $C$ can minimize the total distance $S$ traveled by the schoolchildren.