Example 2 (2006 National High School Mathematics Competition Question) Express 2006 as the sum of 5 positive integers $x_{1}, x_{2}, x_{3}, x_{4}$, $x_{5}$. Let $S=\sum_{1 \leqslant i<j \leqslant 5} x_{i} x_{j}$. Questions:
(1) For what values of $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$ does $S$ attain its maximum value;
(2) Suppose for any $1 \leqslant i, j \leqslant 5$, $\left|x_{i}-x_{j}\right| \leqslant 2$, for what values of $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$ does $S$ attain its minimum value.
(1) First, the set of such $S$ values is bounded, so there must be a maximum and a minimum value.
If $x_{1}+x_{2}+x_{3}+x_{4}+x_{5}=2006$, and $S=\sum_{1 \leqslant i x_{1} x_{2}$.
Rewrite $S$ as $S=\sum_{1 \leqslant i0$, which contradicts the fact that $S$ reaches its maximum value at $x_{1}, x_{2}, x_{3}, x_{4}, x_{5}$. Therefore, it must be that $\left|x_{i}-x_{j}\right| \leqslant 1(1 \leqslant i, j \leqslant 5)$. Thus, the maximum value is achieved when $x_{1}=402, x_{2}=x_{3}=x_{4}=x_{5}=401$.
(2) When $x_{1}+x_{2}+x_{3}+x_{4}+x_{5}=2006$ and $\left|x_{i}-x_{j}\right| \leqslant 2$, only the following three cases satisfy the requirements: (1) $402,402,402,400,400$; (2) $402,402,401,401,400$; (3) $402,401,401,401,401$.

The last two cases are obtained by adjusting $x_{i}^{\prime}=x_{i}-1, x_{j}^{\prime}=x_{j}+1$ from the first case. According to the solution process in (1), each adjustment increases the sum $S=\sum_{1 \leqslant i<j \leqslant 5} x_{i} x_{j}$, so the minimum value is achieved when $x_{1}=x_{2}=x_{3}=402, x_{4}=$ $x_{5}=400$.