A (not necessarily continuous) function on a compact metric space attaining its maximum. I am studying for an exam and my study partners and I are having a dispute about my reasoning for $f$ being continuous by way of open and closed pullbacks (see below).  Please help me correct my thinking.  Here is the problem and my proposed solution:
Let $(K, d)$ be a compact metric space, and let $f: K \rightarrow \mathbb{R}$ be a function satisfying that for each $\alpha \in \mathbb{R}$ the set {$x \in K: f(x) \ge \alpha$} is a closed subset of $K$.  Show that $f$ attains a maximum value on $K$.
Proof: Notice that $A :=$ {$x \in K: f(x) \ge \alpha$} is precisely $f^{-1}[\alpha, \infty)$.  Since $[\alpha, \infty)$ is closed in $\mathbb{R}$ and $A$ is assumed to be closed in $K$, then it follows that $f$ is continuous on $A$.  On the other hand, $K-A = f^{-1}(-\infty, \alpha)$ is open in $K$ since $A$ is closed in $K$.  And since $(\alpha, \infty)$ is open in $\mathbb{R}$ and $K - A$ is open in $K$, then if follow that $f$ is continuous on $K - A$, hence $f$ is continuous on $K$.  Since $K$ is compact and $f$ is continuous, then $f(K)$ is compact in $\mathbb{R}$.  Compact sets in $\mathbb{R}$ are closed and bounded intervals.  Thus $\sup{f(K)} = \max{f(K)} = f(x_0)$ for some $x_0 \in K$.  Thus $f$ indeed attains its maximum value on $K$.  $\blacksquare$

Here is a complete proof with sequential compactness:
Suppose that $f$ has no maximum on $K$. Then there are two cases:
Case 1: $\sup_{x \in K} f(x) = \infty$. 
Then for any $n \in \mathbb{N}$ there is some $x_n \in K$ such that $f(x_n) > n$. Since $K$ is compact there exists a subsequence $x_{n_k} \in K$ that converges to some $x \in K$. Let $A = \{y \in K| f(y) > f(x)+1\}$. Then $x_{n_k} \in A$ for sufficiently large $k$, but $x \not \in A$. Therefore $A$ is not closed.
Case 2: $\sup_{x \in K} f(x) = L \in \mathbb{R}$. 
Then for any $n \in \mathbb{N}$ there is some $x_n \in K$ such that $f(x_n) > L - \frac{1}{n}$. Again since $K$ is compact there exists a subsequence $x_{n_k} \in K$ that converges to some $x \in K$. Because $f$ attains no maximum, we have $f(x) < L$. Let $A = \{y \in K| f(y) > \frac{f(x)+L}{2}\}$. Then $x_{n_k} \in A$ for sufficiently large $k$, but again $x \not \in A$. Hence $A$ is not closed as in Case 1. $\blacksquare$
