Continuous function on compact metric space attains maximum value, intuition? I have a question here on a proposition from a real analysis textbook.

If $K$ is compact metric space and $f$ is continuous on $K$ (here $f: K \to \mathbb{R}$), then there exists $x'$ such that $f(x') = \sup_{x \in K} f(x)$, i.e. $f$ takes on its maximum value.

Here is the proof.

Let $M = \sup_{x \in K} f(x)$ and suppose $f(x) < M$ for every point in $K$. If $y \in K$, let $L_y = (f(y) + M)/2$ and let $\epsilon_y = (M - f(y))/2$. By the continuity of $f$, there exists $\delta_y$ such that $|f(z) - f(y)| < \epsilon_y$ if $d(z, y) < \delta_y$. then $G_y = B(y, \delta_y)$ is an open ball containing $y$ on which $f$ is bounded above by $L_y$. Now $\{G_y\}_{y \in K}$ is an open cover for $K$. Let $\{G_{y_1}, \ldots, G_{y_n}\}$ be a finite subcover. Let $L = \max(L_{y_1}, \ldots, L_{y_n})$. Then $L$ is strictly smaller than $M$. If $x \in K$, then $x$ will be in some one of the $G_{y_i}$, and hence $f(x) \le L_{y_i} \le L$. But this says that $L$ is an upper bound for $\{f(x): x \in K\}$, a contradiction to the definition of $M$. Therefore our supposition that $f(x) < M$ for every $x$ in $K$ cannot be true.

I can follow the proof step to step, but I'm interested in the following: if I were to distill this proof down to its essential idea(s), what would they be? What is the intuition behind the proof of this proposition?
 A: The key ideas are (1) if $X$ is compact and $f$ is continuous, then $f(X)$ is compact and (2) compact subsets of $\mathbb{R}$ are bounded (so the infimum and supremum exist) and closed (so the set contains its infimum and supremum).
Applying (2) to the compact subset $f(X)$ of $\mathbb{R}$ shows that $f(X)$ has a maximum and minimum, i.e. that $f$ attains its max and min.
A: I think the current proof is intuitive enough. Its actually quite graphic, but we may make it more verbal, so one may visualise it even more easily.
Let us say that a set $A$ is separated or bounded away from an upper bound $M$ if there exists a clear gap between it and $M$; that is, if there exists a number $s$ such that $a<s<M$ for every $a\in A$.
Now, intuitively, what the proof says is this:


*

*If the supremum $M$ is not attainable, then $f(y)<M$ for each $y\in K$.

*Since $f$ is continuous, we can always grow from each $y\in K$ a sufficiently small open ball $G_y$ whose image $f(G_y)$ is separated from $M$.

*As each $G_y$ is centred at $y$, the union of these balls covers $K$.

*It follows from the compactness of $K$ that we can pick a finite cover $G_{y_1},\ldots,G_{y_n}$ of it.

*As each $f(G_{y_k})$ is separated from $M$, so is their finite union $\bigcup_{k=1}^n f(G_{y_k})$. (The finiteness is essential here. See also this discussion of "Why is compactness so important?")

*In turn, $f(K)\subseteq f\left(\bigcup_{k=1}^n G_{y_k}\right)=\bigcup_{k=1}^n f(G_{y_k})$ is separated from $M$ too.

*But this is a contradiction, because $M$ is the supremum of $f(K)$ and the supremum of a set, by definition, cannot be separated from the underlying set.

*Therefore the supremum $M$ must be attainable.

A: Note that the given proof is flawed since it is tacitly assumed that $M<\infty$.
Nevertheless, the key idea is the following: If $f(y)<M$ for all $y\in K$, then you can choose for each point $y\in K$ a number $L_y$ with $f(y)<L_y<M$, and then by continuity a small open neighborhood $G_y$ of $y$ such that $f(x)\leq L_y$ for all $x\in G_y$. 
The family $\bigl (G_y\bigr)_{y\in X}$ is an open cover of $X$. Since $K$ is compact we can select a finite subfamily $\bigl(G_{y_k}\bigr)_{1\leq k\leq N}$ in such a way that the $G_{y_k}$ already cover all of $K$. 
Now the bounds $L_y$ come in: Put $\max_{1\leq k\leq N} L_{y_k}=:L$. I claim that $f(x)\leq L$ for all $x\in K$, in other words: $L$ is an upper bound of the set $\{f(x)\,|\,x\in K\}$. – Proof: Given any $x\in K$ this point $x$ is contained in one of the selected $G_{y_k}$. It follows that $f(x)\leq L_{y_k}\leq L$.
On the other hand   $L<M$ since each of the finitely many $L_{y_k}$ is $<M$. This contradicts the definition of $M$. It follows that our working assumption "$f(y)<M$ for all $y$" cannot be upheld.
A: The result is valid for any non-empty space $ X $ with the compactness property. And a previous answer points out that a proof by contradiction cannot start by assuming $\infty\ne M=\sup \{f(x):x\in X\}.$
Whether $M$ is finite or not, the main idea is that if $f(x)\ne M$ for every $x\in X,$ then for every $x\in X$ there is a bounded open real subset $U(x)$ such that $f(x)\in U(x)$ and $M>\max \overline {U(x)}.$ Note that $\{f(y):y\in f^{-1}U(x)\}\subset U(x)$ because $f$ is a function. So we have $$\sup \{f(y):y\in f^{-1}U(x)\}\leq \sup U(x)=\max \overline {U(x)}<M.$$
Now if $\{f^{-1}U(x_j):j=1,...,n\}$ is a finite sub-cover of the open cover $\{f^{-1}U(x): x\in X\} $  then the contradiction is $M=\sup \{f(x):x\in X\}=\max_{j=1,...,n}\sup\{f(y):y\in f^{-1}U(x_j)\}\leq \max_{j=1,...,n}\max \overline {U(x_j)}<M.$ (Because $\{\max \overline {U(x_i)}\}_{j=1,...,n}$  is a finite set of reals, each less than $M.$)
Remark: Any statement about open sets has a corresponding dual statement about their complements, the closed sets.
When $F$ is a family of subsets of $X$ we say $F$ has the Finite Intersection Property (FIP) to mean that any finite non-empty $G\subset F$ satisfies  $\cap G\ne \emptyset.$
If a space is compact then any non-empty family $F$ of closed subsets of $X$ that has the FIP satisfies $\cap F\ne \emptyset.$ Otherwise $\{X$ \ $s : s\in F\}$ is an open cover with no finite sub-cover. (The converse also holds.)
Now if $X$  is  non-empty and compact , and if the continuous $f:X\to \mathbb R $ does not attain its maximum, then with $M$ as above, $f^{-1}[r,M)$ is not empty and is closed in $X$ for every $r<M$.  (Its complement in $X$ is  $f^{-1}(-\infty,r)$ because  $y\in X \implies f(y)<M.$)
But if $G=\{f^{-1}[r_j,M)\}_{j=1,...,n}\subset F=\{f^{-1}[r,M):r<M\}$ then with $r=\max_{j=1,...,n}r_j$ we have $\cap G=f^{-1}[r,M)\ne \emptyset.$  So $F$ is a non-empty family of closed subsets of $X$, and $F$ has the FIP . But $\cap F=\emptyset,$ a contradiction.    
A: One thing I note about this proof is it presumes $f(K)$ is bounded and a $\sup_{x\in K} f(x)$ exists and states so without proof.  So that is not one of key points of the proof.  Which is fair as continuous functions map compact sets to compact sets is a previously proven theorem.
I bring this up because in an ambushed situation where a person springs a "Quick!  What is an outline proof that a continuous function acheives a maximum value on a compact set" I'd immediate think that function being bounded as a more important and more subtle factor than that the function achieves the sumpremum at a point of the set.
But that was not the question.
You want an "intuitive proof" so although this is a proof by contradiction I'll modify it to a direct proof so we can "see" the point of maximum achievement.
So key points:  
The supremum for $f(K)$ exists and is $M$. 
Let $y$ be such $f(y) < M$. i.e. $y$ doesn't achieve maximum. 
We can find $L_y$ so $f(y) < L_y < M$.
$f$ is continuous so there are $\delta_y$ for each $y$ so that $z \in B(y, \delta_y)$ means $f(z) < L_y < M$.
The $B(y, \delta_y)$s form an open cover for all the points that do not acheive maximum.
Take any finite subset of these $B(y, \delta_y)$
For any $z \in B(y_i, \delta_{y_i})$ means $f(z) < \max(L_{y_i})< M$ for the maximum of a finite values of $L_{y_i}$.
Thus $\max(L_{y_i}$ is an upperbound of the image of points in thes finite set of $B(y_i, \delta_{y_i})$.  But $\max(L_{y_i} < M$ so it isn't an upperbound of $f(K)$. So no finite subcover of $B(y, \delta_y)$ cover the compact $K$. So $B(y, \delta_y)$ can't be an open cover of $K$ and there must be so $y$ acheiving the maximum.
A: The key idea is that, assuming $f$ is bounded and the supremum is not attained (so the function has no maximum), then we can build an open cover of $X$ that has no finite subcover.
I believe that the proof by contradiction hides the main idea.
Case 1: $f$ is upper bounded.
Let $M=\sup\{f(x):x\in K\}$ and suppose $f(x)<M$, for every $x\in K$. Let $n>0$ be an integer. By definition of supremum, the set $A_n=f^{-1}\bigl((M-1/n,M)\bigr)$ is not empty. Set also $A_0=f^{-1}\bigl((-\infty,M-1/2)\bigr)$. Then
$$
K=\bigcup_{n\ge0}A_n
$$
so we have an open cover of $K$ that has no finite subcover.
Case 2: $f$ is not upper bounded.
For $n>0$, set $B_n=f^{-1}\bigl((n,\infty)\bigr)$ and $B_0=f^{-1}\bigl((-\infty,2)\bigr)$. Then $B_n$ is not empty, for $n>0$, and
$$
K=\bigcup_{n\ge0}B_n
$$
so we have an open cover of $K$ that has no finite subcover.
