I asked the following questions which is special case of the current question:
How to show maximizer of an inner product over a convex set happens on the boundary?
I want to prove it rigorously.
Let $f: \mathbb{R}^n \rightarrow \mathbb{R}$ be a convex function and $ C \in \mathbb{R}^n$ be a closed and bounded convex set. Rigorously, how one can show the maximizer of a convex set lies on the boundary?
$C$ is compact, so a maximizer does indeed exist. If $f$ is constant, then every point is a maximizer (which of course include every boundary point). So assume $f$ is not constant and let $c\in C$ be a maximizer. As $f$ is not constant, there exists $x\in C$ such that $f(x)\ne f(c)$. As $c$ is a maximizer, $f(x)<c$. For $t\in \Bbb R$, let $\gamma(t)=c+t(c-x)$. Assume $\gamma(t)\in C$ for some $t>0$. Then by convexity of $f$ applied to the points $x,c,\gamma(t)$, $$f(\gamma(t))\ge f(c)+t(f(c)-f(x))>f(c),$$ contradiction. Hence $\gamma(t)\notin C$ for all $t>0$. We conclude that $c\in\partial C$.