$u$ upper semicontinuous iff for all $K \subseteq U$ compact and $g \in C(K)$, $u - g$ attains its maximum on $K$? As the question title suggests, how do I see that $u$ is upper semicontinuous if and only if, for all $K \subseteq U$ compact and $g \in C(K)$, the difference $u - g$ attains its maximum on $K$?
 A: $\impliedby$: Because $u - 0=u$ has the maximum property on compact sets, $u$ is bounded above on each compact set.
Suppose, to reach a contradiction, that $x_0\in U$ and
$$u(x_0) < \limsup_{x\to x_0} u(x) = L.$$
Choose a sequence $x_n \to x_0$ such that $u(x_n) \to L.$ Let $K= \{x_n: n \in \mathbb N \}\cup \{x_0\}.$ Then $K$ is compact. Define $g(x_n) = u(x_n), g(x_0) =L.$ Then $g\in C(K).$ Also the function $h(x) = d(x,x_0)\in C(K).$ By our assumption, $ u-(g+h)$ has the maximum property on $K.$ But $u-(g+h)<0$ on $K,$ while $u(x_n)-(g(x_n)+h(x_n)) = -h(x_n) \to 0.$ Thus the maximum value of $u-(g+h)$ does not exist on $K,$ contradiction.
A: Here's the first half to get you started...
A function $u\in C(U)$ is upper semicontinuous provided that for all $x \in U$, and for all sequences $(x_n)_{n=1}^{\infty}\subset U$ such that $x_n \rightarrow x$, $$\limsup u(x_n) \leq u(x)$$
I make the assumption that you're considering real-valued functions on a metric space.
($\implies$)
First we show that $u$ is bounded above on $K$. Assume $u$ is not bounded above. Then there exists a sequence $(x_n) \subset K$ such that $u(x_{n+1})>u(x_n)+1$ for each $n$. As $K$ is compact, there exists a convergent subsequence $(x_{n_{k}}) \rightarrow x \in K$, and as $u$ is upper semicontinuous, $\limsup u(x_{n_k}) \leq u(x)$. But this would imply $u(x)=\infty$, so $u$ is bounded above.
As $u(K)$ is bounded, it has a least upper bound $M$ meaning we can construct a sequence $(x_n)$ such that $f(x_n) > M - 1/n$. Again, as $K$ is compact we take a convergent subsequence $x_{n_k}\rightarrow x\in K$ and note that for each $n$ we have $$M-1/n<u(x_{n_k})\leq u(x) \leq M$$ so $u(x)=M$. 
As $g$ is a continuous function we have $\lim g(x_n) \leq g(x)$, so $\limsup (u-g)(x_n) \leq (u-g)(x)$ and $u-g$ is upper semicontinuous. We can then apply the above argument.
