A problem on discontinuous function

a function $f:\mathbb{R}\rightarrow \mathbb{R}$ has at least one local min and at least one local max. Also all its local max values are less than its local min values. (i.e. if $f$ attains local max at $a$, and local min at $b$, then $f(a) < f(b)$). Show that $f$ must be discontinuous. Is it true?

-
No Dear Sir.What is that? – Un Chien Andalou Apr 2 '12 at 5:55
@MimMim if someone answers your question to your satisfaction, you must click the green check mark next to the answer so that person gets credit. Otherwise, no one will answer your questions anymore. – Parsa Apr 2 '12 at 6:28
Imagine if your function is continuous. Suppose $f$ hits it local max at $a$. By definition of local max, in an interval $I$ containing $a$, $f(x)<f(a)$ for all $x \in I$. Now, if $f(b)>f(a)$ for a local min at $b$, show there had to have been another local min $c$ with $f(c)<f(a)$. – Parsa Apr 2 '12 at 6:35
Dear Sir Parsa, Thank you very much. – Un Chien Andalou Apr 2 '12 at 7:02
Concerning accepting answers,you can see some useful information at math.stackexchange.com/faq#howtoask, also see the discussion at meta.math.stackexchange.com/questions/3399/…. – Gerry Myerson Apr 2 '12 at 7:02

The reasoning by @Parsa has a minor omission; however it is easily repaired. The issue concerns the definition of local extrema. The definition of local min at $a$ is that there is an open interval $I$ containing $a$ such that $f(x) \ge f(a)$, $\forall x \in I$ (ie, the inequality is not strict).
However, since all local max values are strictly less than the local min values, this means that if $f$ is continuous, then no other point in $I$ (other than $a$) can have the value $f(a)$ (for either a max or a min). To see this, suppose $a$ is a local min, and that $a' \in I$ also satisfies $f(a') = f(a)$. Then $f$ must have a local max between $a$ and $a'$ whose value is not strictly less than $f(a)$, which is a contradiction. Consequently, $f(x) > f(a)$, $\forall x \in I \setminus \{a\}$. The same reasoning applies to a local max, mutatis mutandis.