We will choose $x \equiv ay \pmod{p}$ so that $x^2 = a^2y^2 \equiv -2y^2 \pmod{p}$, and so $p \mid x^2 + 2y^2$. We want to choose $y > 0$ so that both $y$ and $ay \pmod{p}$ are small. For a $t$ to be chosen later, consider the values $x_s = sy \pmod{p}$ for $s=1,\ldots,t$. Since there are $t$ values, there must be two values, say $s_1,s_2$, such that $x_{s_2} - x_{s_1} \leq p/s$ (measured on the circle $\mathbb{Z}_p$). Taking $r = s_2-s_1$, we deuce that $0 < r < s$ and $0 < x_r < p/s$. In particular, choosing $s = \lceil \sqrt{p} \rceil$ we obtain $0 < r \leq \sqrt{p}$ and $0 < x_r < \sqrt{p}$. Taking $y = r$ and $x = x_r$, we deduce $p \mid x^2 + 2y^2$ while $0 < x^2 + 2y^2 < 3p$, and so $x^2 + 2y^2 \in \{p,2p\}$.