Let $X$ be a metric space. For nonempty subsets $A,B\subseteq X$. Define $\text{dist}(A,B) := \inf\{d(x,y) : x\in A, y\in B\}$
a) Prove that if $A$ is compact and $B$ is closed and $A\cap B = \emptyset$ then $\text{dist}(A,B) > 0$
b) Suppose that $X = \mathbb{R}^n$, with the standard metric. Under the same assumptions of (a), prove that $\exists x_0\in A$ and $\exists y_0\in B$ such that dist$(A,B) = ||x_0 - y_0||$.
For a), it seems to me that the crucial point is that $A\cap B = \emptyset$. I can immediately see how this would imply that $\text{dist}(A,B) > 0$. However, I do not understand why it's necessary for $A$ to be compact, and $B$ to be closed. Could you explain why those conditions are necessary?