Problem involving maximum and minimum of a continuous function Let $f:\mathbb{R}\to\mathbb{R}$ be a continuous function. We denote, for every $x\in\mathbb{R}$, with $m(x)$ and $M(x)$ the minimum and maximum of $f$ on the interval $[x-1,x]$. Show that, if $m(x)+M(x)=0,\forall x\in\mathbb{R}$, then the functions $m$ and $M$ are constant.
I have tried to prove that $f$ is periodic, but I didn't managed to do it; I'm not sure it's even true...
 A: Since $f$ is continuous on $[x-1,x]$, its min and max on this interval are attained : there are $a,b$ in $[x-1,x]$ such that $f(a)=m(x)=-M(x)$ and $f(b)=M(x)$.
Lemma 1. For any $x\in{\mathbb R}$, there is an $\varepsilon \gt 0$ such that $M(y)\geq M(x)$ for any $y\in[x,x+\varepsilon]$.
Proof of lemma 1.  If $a\neq x-1$, for any $y\in [x,a+1]$ we have that $a\in [y-1,y]$ ; it follows that $m(y)\leq f(a)=-M(x)$, and hence $M(y)\geq M(x)$. We may therefore take $\varepsilon = a+1-x$ in this case.
Similarly, if $b\neq x-1$, for any $y\in [x,b+1]$ we have that $b\in [y-1,y]$ ; it follows that $M(y)\geq f(b)=M(x)$. We may therefore take $\varepsilon = b+1-x$ in this case.
We are left with the case $a=b=x-1$. In this case, we must have $m(x)=M(x)=0$, so that $f$ is zero on $[x-1,x]$. But then, we can change the value of $a$ or $b$ and re-apply either of the two arguments above. This finishes the proof of lemma 1.
Lemma 2. M is nondecreasing on $\mathbb R$.
Proof of lemma 2. Let $x_0\in {\mathbb R}$ and $A$ be the set of all $x\geq x_0$ such that $M$ is $\geq M(x_0)$ on $[x_0,x]$. By lemma 1, we know that $A$ contains at least a small right neighborhood of $x_0$. Let $s=\sup(A)$ (so that $s$ is either finite or $\infty$). It follows easily from the definition of $A$ that $[x_0,s) \subseteq A$ and that $M$ is $\geq M(x_0)$ on $[x_0,s)$. If $s$ were finite, we would deduce $s\in A$ by the continuity of $f$, and using lemma 1 a second time, with $s$ instead of $x$, we would deduce $[x_0,s+\varepsilon] \subseteq A$ for small enough $\varepsilon$ - a contradiction. So $s=\infty$, which finishes the proof of lemma 2.
Lemma 3. For any $x\in{\mathbb R}$, there is an $\varepsilon \gt 0$ such that $M$ is constant on $[x,x+\varepsilon]$.
Proof of lemma 3. If $f(x) \neq M(x)$, then since $f$ is continuous we will a have a $\varepsilon \gt 0$ such that $f(y) \lt M(x)$ for $y\in[x,x+\varepsilon]$, whence $M(y) \leq M(x)$ for $y\in[x,x+\varepsilon]$ ; by lemma 2, we deduce $M(y) = M(x)$ for $y\in[x,x+\varepsilon]$ and we are done.
If $f(x) \neq m(x)$, then since $f$ is continuous we will a have a $\varepsilon \gt 0$ such that $f(y) \gt m(x)$ for $y\in[x,x+\varepsilon]$, whence $m(y) \geq m(x)$ for $y\in[x,x+\varepsilon]$ ; using $M=-m$, we can finish the argument as in the paragraph above.
We are left with the case $f(x)=m(x)=M(x)$. Then $m(x)=M(x)=0$, so that $f$ is zero on $[x-1,x]$.
If $M$ is still zero on $[x,x+\frac{1}{2}]$, taking $\varepsilon=\frac{1}{2}$ we are done. So, we can assume that there is a $K\gt 0$ which is attained by $M$ on $[x,x+\frac{1}{2}]$.
Let $Z=\bigg\lbrace z \in [x,x+\frac{1}{2}] \bigg| M(z)=K \bigg\rbrace$. By hypothesis, $Z$ is non-empty. Let $z\in Z$. We have $a,b\in [z-1,z]$ such that $f(a)=m(z)=-K,f(b)=M(z)=K$. Those two values are distinct, so one of $a$ or $b$ (call it $z'$) is $\neq z$. Since $f$ is zero on $[z-1,x]$, $z'$ cannot be in this interval, so that we must have $x \lt z' \lt z$. Since $|f(z')|=K$, we must have $M(z') \geq K$ ; but the reverse inequality also holds by lemma 2. So $M(z')=K$, and hence $z'\in Z$.
We have therefore shown the following : $(\star)$ for any $z\in Z$, there is a $z'\in Z$ such that $z' \lt z$ and $|f(z')|=K$.
Let $\zeta = \inf(Z)$. There is a decreasing sequence $(z_n)_{n\geq 1}$ of elements of $Z$ convergeing to $\zeta$. By $(\star)$, for each $n$ there is a $z'_n\in Z$ such that $z'_n \lt z_n$ and $|f(z'_n)|=K$. Passing to the limit when $n\to\infty$, by the continuity of $f$ we must have $|f(\zeta)|=K$. But then $\zeta \in Z$, and using $(\star)$ for $z=\zeta$ we see that $\zeta$ is not the $\inf$ of $Z$, contradiction. This finishes the proof of lemma 3.
Lemma 4. M is constant on $\mathbb R$.
Proof of lemma 4. Same as  the deduction of lemma 2 from lemma 1, with "$\geq M(x_0)$" replaced by "constant".
