Example 5 Express 2006 as the sum of 5 positive integers $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$, and let $S=$ $\sum_{1 \leqslant i<j \leq 5} x_{i} x_{j}$. Questions:
(1) For what values of $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$, does $S$ reach its maximum value;
(2) Furthermore, if for any $1 \leqslant i, j \leqslant 5$, $\left|x_{i}-x_{j}\right| \leqslant 2$, then for what values of $x_{1}, x_{2}, x_{3}$, $x_{4}, x_{5}$ does $S$ reach its minimum value, explain the reason. (2006 National High School Mathematics Joint Competition Test
(1) First, the set of such $S$ values is bounded, so there must exist a maximum and a minimum value.
If $x_{1}+x_{2}+x_{3}+x_{4}+x_{5}=2006$, and $S=\sum_{1 \leq i < j \leq 5} x_{i} x_{j}$ is maximized.

Rewrite $S$ as
$$S=\sum_{1 \leq i < j \leq 5} x_{i} x_{j}.$$
If there exist $x_{i}, x_{j}$ such that $|x_{i}-x_{j}| > 1$, without loss of generality, assume $x_{1} > x_{2} + 1$. Let $x_{1}' = x_{1} - 1$ and $x_{2}' = x_{2} + 1$. Then
$$S' = \sum_{1 \leq i < j \leq 5} x_{i}' x_{j}' = S + (x_{1} - x_{2} - 1) > S,$$
which contradicts the assumption that $S$ is maximized at $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$. Therefore, it must be that $|x_{i} - x_{j}| \leq 1$ for all $1 \leq i, j \leq 5$. Thus, $S$ is maximized when $x_{1} = 402$ and $x_{2} = x_{3} = x_{4} = x_{5} = 401$.
(2) When $x_{1}+x_{2}+x_{3}+x_{4}+x_{5}=2006$ and $|x_{i}-x_{j}| \leq 2$ for all $1 \leq i, j \leq 5$, only the following three cases satisfy the requirement:
( I ) 402, 402, 402, 400, 400;
(II) 402, 402, 401, 401, 400;
(III) 402, 401, 401, 401, 401.

The last two cases are obtained by adjusting the first case: $x_{i}' = x_{i} - 1$ and $x_{j}' = x_{j} + 1$. According to the proof in (1), each adjustment increases the sum $S = \sum_{1 \leq i < j \leq 5} x_{i} x_{j}$. Therefore, $S$ is minimized when $x_{1} = x_{2} = x_{3} = 402$ and $x_{4} = x_{5} = 400$.