Monotonic everywhere function $f: \mathbb R \to \mathbb R,\forall x \in \mathbb R $ $\exists \delta \gt 0 : f$ is non-decreasing on $(x-\delta,x+\delta)$(I call that statement A). I need to prove that $f$ is non-decreasing on $\mathbb R$ (statement B).
I tried to go backwards: $\lnot B \implies \lnot A$. In words, that would be: if there is such $x_1,x_2 \in \mathbb R, x_1 \lt x_2, f(x_1)\gt f(x_2)$, then $\exists x\in \mathbb R, \forall \delta \gt 0 $ $\exists x_3,x_4 \in (x-\delta,x+\delta), x_3 \lt x_4, f(x_3) \gt f(x_4)$. I should find $x$ by using $x_1,x_2$. My problem is that I don't know how to do that. I know I supposed to use supremum of some set, but no more than that. Can somebody help me with that?
 A: Sketch: You can attempt a direct argument by considering the sets
\begin{align*}
X^{+} &= \{x > 0 : \text{$f$ is non-decreasing on $[0, x]$}\}, \\
X^{-} &= \{x < 0 : \text{$f$ is non-decreasing on $[x, 0]$}\}.
\end{align*}
Your statement A implies $X^{+}$ is non-empty and open. If $\ell = \sup X^{+}$ existed (i.e., were finite), statement A (with $x = \ell$) would get you into a contradiction; consequently, $\sup X^{+} = +\infty$, and $f$ is non-decreasing on $[0, \infty)$. A similar argument shows $\inf X^{-} = -\infty$.
(This strategy looks more straightforward than the contrapositive, though consideration of similar sets will help if you decide to proceed with the contrapositive.)
A: This is a standard argument based on compactness. Take $x<y$ and consider the compact interval $I=[x,y]$. Around each $x \in I$ you may find a small neighbourhood of the form $U_x=(x-\delta_x, x+\delta_x)$ on which your function is non-decreasing. Since $I \subset \bigcup \limits _{x \in I} U_x$ and I is compact, then there is a finite sub-covering of $I$ of the form $\bigcup \limits _{i=1} ^n U_{x_i}$ with $x_i \in I \space \forall i = 1 \dots n$ and $x_i < x_{i+1}$.
Now let $a \in U_{x_1} \setminus U_{x_2}$ and $b \in U_{x_2} \setminus U_{x_1}$, so $a \leq b$: choose some $c$ between $a$ and $b$, $c \in U_{x_1} \cap U_{x_2}$. Since $a,c \in U_{x_1}$, then $f(a) \leq f(c)$. Since $c,b \in U_{x_2}$, then $f(c) \leq f(b)$. Hence, $f(a) \leq f(b)$.
This is in fact a standard type of proof, and it took me more time to write it than it will take you to understand it.
A: Excuse the pedagogue in me (or is it pedant?).  There is a general lesson here.  If you have a local condition (here locally nondecreasing) and you want to derive a global condition (nondecreasing on $\mathbb{R}$) the compactness arguments should immediately come to mind. (Indeed one of the answers specifically invokes the Heine-Borel theorem which is synonymous with compactness.)
On the real line there is a very convenient tool for constructing compactness arguments.  One of my colleagues was a bit worried for his students since they were so addicted to using it that he felt maybe it was a bit unwise, since it doesn't generalize to metric spaces even (as the Heine-Borel theorem does).  The students used the argument exclusively and would avoid any other compactness argument as too tedious.
Here is the argument:  let $\cal C$ be the collection of all intervals $[u,v]$ on which $f$ is nondecreasing.  That's a huge collection because of the assumption that $f$ is locally nondecreasing.  So huge in fact that for any interval $[a,b]$ you can split into pieces 
$$[a,a_1], [a_1,a_2], [a_2,a_3], \dots , [a_n,b]$$
where each of the pieces is in $\cal C$.  So, of course, $f$ is nondecreasing  on $[a,b]$ since it is nondecreasing on each of the pieces.
If you have never seen the argument before (it is in my textbook, but not in all elementary real analysis textbooks) here is what you need.

Definition. A collection  $\cal C$ of closed intervals $[u,v]$ is said to be  full at a point $x$ if there is a $\delta>0$ [$\delta$ depends on $x$] so that
  $[u,v]\in {\cal C}$ whenever $x\in [u,v]$ and $v-u<\delta$.
Cousin Covering Lemma:  If $\cal C$ is full at every point of an
  interval $[a,b]$ then $\cal C$ contains a partition of $[a,b]$.

With this tool available the solution to the posed problem is fast and simple: Let  $\cal C$ be the collection of all intervals on which $f$ is nondecreasing.  This is full at each point by the assumption that $f$ is locally nondecreasing.  Since   $\cal C$ contains a partition of any interval $[a,b]$ [by Cousin's lemma], $f$ is nondecreasing on every interval.
