Riemann integrable function which does not take its maximum on the interval

I made the following assertion on an exam I thought was true:

If a function is Riemann-integrable on $[a,b]$ then it attains its maximum on the interval.

Apparently this is false. This is definitely true if $f$ is continuous. Thus I'm trying to argue that there exists a discontinuous function that is Riemann-integrable and does not attain its max on the interval. I'm having a tough time though -- ideas?

Edit: Sorry for all the edits!

• A simple example is taking a continuous function on a compact set, which attains its maximum, and then removing the maximum (so you have a single hole-type discontinuity where the maximum is) and replacing that value with something else. The integral remains the same, but the maximum is no longer attained. – rubikscube09 May 20 '18 at 19:41
• @rubikscube09: That won't work as written for an arbitrary continuous function on a compact interval -- consider a "flat-topped" function such as $x\mapsto3-|x-1|-|x-2|$ on $[0,3]$. Removing all the maxima will leave too large a hole to fill in without changing the integral. – Henning Makholm May 20 '18 at 19:58
• So after graphing I see that the function is constant and maximal on the interval $[1,2]$. Would we lose integrability if we shifted that entire interval by some value? It seems that we would only have 2 discontinuity points in that case. – rubikscube09 May 20 '18 at 20:07

How about $$f(x) = \begin{cases} 1-x^2 & \text{when }x\ne 0 \\ 0 & \text{when }x=0 \end{cases}$$ on $[-1,1]$?
This is Riemann integrable because a Riemann sum for it differs from a Riemann sum for $1-x^2$ by at most the width of the subinterval containing $0$. So we can make the difference as small as we want by insisting on a sufficiently fine partition.