Let $(x_i)_{i=1}^{i=n}, (y_i)_{i=1}^{i=n}$ are sequence of positive numbers with $\sum_{i=1}^{n}x_i=\sum_{i=1}^{n}y_i=1$. Prove that $\sum_{i=1}^{n}x_iy_i$ is maximized when $x_i$ and $y_i$ are roughly the same size (More precisely, when $x_1>x_2>\cdots > x_n$ and $y_1>x_y>\cdots > y_n$).
I have seen an algebraic proof long time ago, but I couldn't write the solution again. Can anyone help?