Upper semicontinuous function attains its supremum 
Definition. Let $X$ be a topological space. A function $f: X \to [-\infty,\infty)$ is said to be upper semicontinuous if for every $x_0 \in X$ and $M > f(x_0)$ a neighbourhood $U$ of $x_0$ exists such that $M > f(x)$ holds for every $x \in U$. 

Now I want to prove, that if $X$ is a compact space, then $f$ attains its supremum. Any hints how to start? $X$ compact means that for every open cover there is a finite subcover but somehow I do not see how this helps. Should I better work with the criterion by sequences?
 A: If you stare at the definition of upper semicontinuity long enough, you will find that the following is an equivalent characterization:

$f : X \to [-\infty, + \infty )$ is upper semicontinuous iff for each $a \in (-\infty, +\infty)$ the inverse image $f^{-1} ( [ -\infty , a ) )$ is open.

To prove that each upper semicontinuous function on a compact space attains a maximum, we take two steps. So let $f : X \to [-\infty , + \infty )$ be an upper semicontinuous function with $X$ compact.

*

*First show that (the image of) $f$ is bounded above.
proof idea. Otherwise the family $\{ f^{-1} ( [-\infty , n ) ) : n \in \mathbb{N} \}$ is an open cover of $X$ with no finite subcover.


*Since it is bounded above, then $\alpha = \sup_{x \in X} f(x)$ exists. By definition of $\alpha$ we know that $f(x) \leq \alpha$ for all $x \in X$, so to show that this supremum is attained we just need to show that it is impossible for $f(x) < \alpha$ to hold for each $x \in X$.
proof idea. If $f(x) < \alpha$ for all $x \in X$, then the family $\{ f^{-1} ( [-\infty , \alpha - \frac{1}{n} ) ) : n \in \mathbb{N} \}$ is an open cover of $X$, and has no finite subcover.
