Let $X$, $Y$ be subsets of $\Bbb{R}$, with $X$ compact and $Y$ closed. Show that there exists $x_0 \in X$, and $y_0 \in Y$ such that $|x_0-y_0| \leq |x-y|$ for all $x \in X$, $y \in Y$.
If $Z = \{|x-y| : x\in X, y\in Y\}$, then $0$ is a lower bound of $Z$ so there exists $\alpha = \inf Z$. So there is a sequence of elements in $Z$ such that it converges to $\alpha$, this means that there are sequences $(x_n)$ in $X$ and $(y_n)$ in $Y$ such that $\lim |x_n-y_n| = \alpha$. Now, because $X$ is compact, then there is a convergent subsequence of $(x_n)$, $(x_{n_k})$ and it could converge to an $x_0$ in $X$ (because $X$ is closed). But I am stuck here, I think what I need is $(x_n)$ to be convergent but that does not necessarily happen here.
$|y_{n_k} - x_{n_k}| \to \alpha$ and $x_{n_k} \to x_0$ as $k \to \infty$, so the possible limit points of $(y_{n_k})_k$ are $x_0 \pm \alpha$. One of them must contain infinitely many points of the sequence $(y_{n_k})_k$ (by "Pigeon-Hole Principle"), and name this point $y_0 \in Y$. ($Y$ is closed.)
We claim that $x_0 \in X$ and $y_0 \in Y$ minimises $|x-y|$: suppose there exists $x_1 \in X$ and $y_1 \in Y$ such that $|x_1-y_1| < |x_0-y_0|$, then $|x_1 - y_1| \in Z$, so that $\alpha \le |x_1 - y_1|$. However, $|x_0 - y_0| = \alpha$ by construction, so $|x_0 - y_0| \le |x_1 - y_1|$, which contradicts the assumption on $x_1$ and $y_1$.