Solution (source code)

= Solution

Let $S=\sum_i p_ia_i>0$ and set $x_i=a_i/S$. Then $x_i>0$ and $\sum_i p_ix_i=1$, so part (1) gives
$$
1\geq\prod_i x_i^{p_i}
=\frac{\prod_i a_i^{p_i}}{S^{\sum_i p_i}}
=\frac{\prod_i a_i^{p_i}}S.
$$
Therefore the <weighted arithmetic-geometric mean inequality> is
$$
\boxed{\prod_i a_i^{p_i}\leq\sum_i p_ia_i.}
$$
Equality holds exactly when all $a_i$ are equal, by the equality case in part (1).