Assume that $(X,d)$ is a metric space and that $f \colon X \to [0, \infty)$ is a continuous function. Assume that for each $\epsilon > 0$, there is a compact set $K_{\epsilon} \subseteq X$ such that $f(x) < \epsilon$ when $x \notin K_{\epsilon}$. Our task is to show that $f$ has a maximum point.
My process for solving this problem is the following. We first need a wise choice for $\epsilon$, let that be $f(z)$ for some $z \in X$. We now know that $f(x) < f(z)$ for all $x \notin K_{f(z)}$. Now, $z$ is clearly a candidate for the global maximum, but we turn our attention to the compact subset $K_{f(z)}$. The latter itself has a maximum point, say $c$, for which $f(c) \geq f(x)$ for all $x \in K_{f(z)}$. Here is the part where I cannot proceed. My guess is that it is either the case that $z \in K_{f(z)}$ in which case we have a global maximum at $c$. But this does not have to be the case; I mean, the only thing that we know so far is (roughly speaking) that $z$ is the maximum for $K_{f(z)} \setminus X$ and $c$ for $K_{f(z)}$, it is also not obvious to me why $f(c) \geq f(z)$. How do I draw a conclusion here? Can I just say that either $z$ or $c$ is the maximum?
I claim that if $f(c) \geq f(z)$, then $c$ is a maximum point. Otherwise, if $f(c) \leq f(z)$, then $z$ is a maximum point. In either case, a maximum point exists.
Indeed, if $f(c) \geq f(z)$, when $x \notin K_{f(z)}$, we have $f(x) < f(z) \leq f(c)$. When $x \in K_{f(z)}$, by definition of $c$ we have $f(x) \leq f(c)$. Hence, for all $x$, $f(x) \leq f(c)$.
If $f(c) \leq f(z)$, when $x \notin K_{f(z)}$, we have $f(x) < f(z)$. When $x \in K_{f(z)}$, by definition of $c$ we have $f(x) \leq f(c) \leq f(z)$. Again, we have that, for all $x$, $f(x) \leq f(z)$.
In either case, we have shown the existence of a maximum point, so we're done.