Lower semicontinuous is defined similarly, with the inequality reversed. Verify that f is continuous iff it is lower and upper semicontinuous. Hint, an open interval is the intersection of two rays.
Let f and g be upper semicontinuous, with f+g = h. If h(x) is bounded below u, let the difference be ε. Now the reals below f(x)+½ε have, as their preimage under f, an open set V in S. Similarly, W is an open set with g(W) below g(x)+½ε. The intersection is an open set, containing x, whose image under h is below u. The preimage, under h, is covered with open sets, and h is upper semicontinuous.
Let u be the least upper bound of f(S). Build a family of closed sets in R, such that Cn is the set of reals ≥ u-1/n. Let Dn be the preimage of Cn under f, and note that Dn is closed. Also, the collection D1 D2 D3 etc has the finite intersection property. There is always some x in S whose image is arbitrarily close to u. Since S is countably compact, our collection of closed sets has a nonempty intersection. Call this point z. Since f(z) lies in every closed set Cn, and is bounded by u, f(z) = u. In other words, f(S) attains its upper bound.
If f is lower semicontinuous, f(S) attains its lower bound.
Next, verify that the closest or farthest distance from y to V is a continuous function of y. Set δ = ε, and use the triangular inequality.
Let y lie in W and let g(y) be the minimum or maximum distance from y to V. this is continuous into the reals. Reasoning as above, g attains its minimum and maximum. thus V and W exhibit two points that are nearest each other, and two points that are farthest apart.
If V = W, there are two points x and y that lie on opposite sides of V. In other words, |x,y| is the diameter of V.
Select an ε > 0. The reals below ε form an open ray; let On be the preimage of this ray under fn. Since images steadily drop to 0, On is an ascending chain of open sets. Every x gets below ε eventually, so S is covered by the infinite chain On. Choose a finite subcover. If n is the largest index in the finite subcover, fn(S), and all subsequent images of S, lie below ε. Thus the sequence of functions converges uniformly to 0.
Instead of 0, let fn(S) decrease monotonically towards a limit function g(S). We will show g(S) is upper semicontinuous. (The domain S need not be countably compact for this step.)
Select an upper bound u, and a point x in S, with g(x) < u. The images of x approach g(x), so there is some n with fn(x) between g(x) and u. The preimage of the reals below u, under fn, is an open set W in S. All functions beyond n map W to values that are even lower. Thus the limit function g maps W to values below u. Therefore x is contained in an open set W, which is also in the preimage under g. The preimage is covered by open sets, and is open. this holds for all u, hence g is upper semicontinuous.
Now assume fn is also lower semicontinuous for each n. In other words, fn is continuous. Thus g(S) is lower semicontinuous, and continuous.
Let hn(S) = fn(S)-g(S). this is a continuous function, and in particular, it is upper semicontinuous. Furthermore, the sequence of functions hn approaches 0, monotonically, for each x. Apply the earlier result, and the sequence hn(S) approaches 0 uniformly. Therefore fn(S) approaches g(S) uniformly.
In summary, a convergent sequence of continuous, monotonic functions from a countably compact space into the reals converges uniformly.