integral of continuous function over [0,1] is equal to some upper bound of the function implies function is constant This is a small real analysis problem that is a part of another problem I'm tackling, and I strongly believe that the following claim is true, but for some reason I'm unable to prove this using elementary real analysis. Could I please get some hints/advice? I don't think it's hard.
Say $f$ is a continuous real-valued function on $[0,1]$, and $c$ is some upper bound on the function $f$ on $[0,1]$. Also say that $\int_0^1 f(x) dx = c$. Then surely $f$ is equal to $c$  on all of $[0,1]$. Could I please get some help in proving this elementary fact that I believe is true?
 A: So $\displaystyle\int_{0}^{1}(c-f(x))dx=0$, but $c-f(x)\geq 0$, if $c-f(x_{0})>0$ for some $x_{0}\in[0,1]$, then for a small open interval $I$ of $x_{0}$, $c-f(x)>\dfrac{1}{2}(c-f(x_{0}))$ and hence the integral is then $\geq\dfrac{1}{2}(c-f(x_{0}))|I|>0$, a contradiction.
A: Hint. Show that if $g(x):=c-f(x)$ is a non-negative continuous function in $[0,1]$ and
$$\int_0^1 g(x) dx = 0$$
then $g$ is identically zero. Assume by contradiction that $g(x_0)>0$ for some $x_0\in [0,1]$ and use the continuity of $g$ at $x_0$.
P.S. Then see Given $f(x)$, a continuous function on [0, 1] st $f(x)≥0$ for all $x∈[0, 1]$, show that if $\int_0^1 f(x)dx=0$ then $f(x) = 0$ for all $x ∈ [0, 1]$?
A: Assume, 
$f$ continuos on $[0,1]$, $c$ is an upper bound.
$I := \displaystyle \int_{0}^{1} f(x)dx=c.$
By MVT for definite integrals:
$I = f(t)\cdot 1 = c$, where $t \in [0,1].$
$\rightarrow: $
$c$ is the maximum of the function in the interval.
$F(x): = f(x) - c \le 0$, $x \in [0,1]$, 
$\\$ $F$ continuous
1)$F(x) = 0$ , $x \in [0,1]$ , we are done.
2)$F(x) \lt 0$ for a $x_0 \in [0,1]$.
Since continuos there is a $\epsilon$ neighbourhood $B_\epsilon(x_0)$ such that $F(x) \lt 0$ for $x \in B_\epsilon(x_0).$
$I = \displaystyle \int_{0}^{1}F(x)dx =$
$\displaystyle \int_{0}^{x_0 -\epsilon}F(x)dx +\displaystyle \int_{x_0 +\epsilon}^{1}F(x)dx +$
$\int_{x_0 -\epsilon}^{x_0+\epsilon}F(x)dx \lt c.$
Reasoning:
Since $F(x) \le 0$ : The first two integrals are $\le 0$, while the last integral is $\lt 0.$
A contradiction .
Hence $F(x)= 0$ , $x \in [0,1]$.
A: $f$ has maximum and minimum, let us say $f(m):=b$, by Weierstrass. Suppose that $b<c$. By continuity for each $\varepsilon>0$ there exists $\delta>0$ such that $f(x)<b+\varepsilon$ for all $|x-m|<\delta$. Fix $\varepsilon$ sufficiently small. Then
\begin{align}
\int_{[0,1]} f(x)\mathrm{d}x &= \int_{[m-\varepsilon,m+\varepsilon] \cap [0,1]}f(x)\mathrm{d}x+\int_{[0,1]\setminus [m-\varepsilon,m+\varepsilon]}f(x)\mathrm{d}x\\
&\le 2\varepsilon(m+\delta) + (1-2\varepsilon)c < c.
\end{align}
