Consider a compact topological space $X$ and a map $f:X\to\mathbb{R}$ such that each $x\in X$ has a neighborhood where $f$ attains its minimum. Show that $f$ attains its minimum on $X$.
My attempt:
I was thinking of covering $X$ with all the neighborhoods where $f$ attains a minimum, so something like $X\subseteq \bigcup_{x\in X} U_x$. Then, by compactness, there would be a finite subcover. I don't see how I can conclude that a minimum is attained from this information: I could possibly go over all sets of the subcover and take the overall minimum that $f$ attains (which exists, as the subcover is finite), but am I guaranteed that this minimum is the minimum of $f$ on $X$?