TITLE: Any lower semicontinuous function $f: X \to \mathbb{R}$ on a compact set $K \subseteq X$ attains a min on $K$.
QUESTION [12 upvotes]: I've been thinking about this problem for a long time right now, and feel stuck. 
Given that $X$ is a topological space, and that for $f$ to be lower semicontinuous, for any $x \in X$ and $\epsilon > 0$, there is a neighborhood of $x$ such that $f(x) - f(x') < \epsilon$ for all $x'$ in the neighborhood of $x$. Also, for the compact definition, I can only think of using every open cover of $K$ has a finite subcover for the topological definition of compact sets.
I don't know where I went wrong, but I don't see where I used the fact of $K$ being compact. So I'll put what I did.
Suppose that $\inf f(K)$ exists, then let's call it $a \in \mathbb{R}$. By the intermediate value theorem, we know that there exists some $x_0 \in X$ such that $f(x_0) = a$. So given that $f$ is lower-semicontinuous, then for $x_0 \in X$ and $\epsilon > 0$, there is a neighborhood of $x_0$ such that $f(x_0) - f(x') < \epsilon$ for all $x'$ in the neighborhood of $x_0$. Note there is an open set in the neighborhood of $x_0$ that contains $x_0$. Then since $K$ is compact, there is a finite open subcover of $K$. So call this finite subcover of $K$, $J$ and call the open set that contains $x_0$, $L$. Hence, $J \cup L$ is an open cover of $K$ and $f$ attains a minimum on $K$.
If the infimum of $f(K)$ does not exist, then we can't consider the case above. Take any $c \in f(K)$. Consider the set of the form $f_c := \{x \in X | f(x) \leq c\}$. Then we see each  $f_c$ is closed since $f$ being lower-semicontinuous implies $f^{-1}(-\infty,a]$ is closed for any $a \in \mathbb{R}$ and $f(K)$ being unbounded. For all $c \in f(K)$, we have that the intersection of all $f_c$ gives us that the intersection of the $f_c$ is closed. Not sure if this fact is in contrary of $K$ being compact. I got stuck here.

REPLY [7 votes]: So this won't help the person who needed it for homework, but for future visitors, here's an approach which is similar to the one above, but uses a contradiction of compactness.
Suppose $f$ has no minimum in $K$, then $\neg(\exists x\in K)(\forall y\in K)(f(x)\leq f(y))$ which is equivalent to $(\forall x\in K)(\exists y\in K)(f(y)<f(x))$ which is equivalent to $(\forall x\in K)(\exists y\in K)(x\in f^{-1}((f(y), +\infty)))$. 
But this means the collection of open sets $\{f^{-1}((f(y), +\infty)):y\in K\}$ is an open cover of $K$. 
We claim this open cover has no finite subcover.
Suppose $\{y_1, \cdots, y_n\}\subset K$ is finite, and define $N = \displaystyle\arg\min_{1\leq k\leq n}f(y_k)$, then $\displaystyle\bigcup_{1\leq k\leq n}(f(y_k),+\infty) = (f(y_N), +\infty)$. Then we have $\displaystyle y_N\in K$, but  $y_N \notin f^{-1}((f(y_N), +\infty))= f^{-1}(\bigcup_{1\leq k\leq n}(f(y_k),+\infty)) = \bigcup_{1\leq k\leq n}f^{-1}((f(y_k),+\infty))$ and so $\{f^{-1}((f(y_k),+\infty)):1\leq k \leq n\}$ doesn't cover $K$.
This contradicts the compactness of $K$.