TITLE: Prove that $f$ is integrable if and only if $\sum^\infty_{n=1} \mu(\{x \in X : f(x) \ge n\}) < \infty$
QUESTION [13 upvotes]: Problem statement: Suppose that $\mu$ is a finite measure. Prove that a measurable, non-negative function $f$ is integrable if and only if $\sum^\infty_{n=1} \mu(\{x \in X : f(x) \ge n\}) < \infty$.
My attempt at a solution: Let $A_n = \{x \in X : f(x) \ge n\}$. To show that $\sum^\infty_{n=1} \mu (\{x \in X : f(x) \ge n\}) < \infty$ implies $f$ is integrable, the Borel Cantelli lemma tells us that almost all $x \in X$ belong to at most finitely many $A_n$. Thus, the set $\{x \in X : f(x) = \infty\}$ has measure $0$. Now, this, together with the fact that $\mu(X) < \infty$, should give us that $f$ is integrable, but I can't figure out how to prove that! It seems fairly obvious, but I can't figure out if it is then ok to say that $f$ is bounded almost everywhere? It seems like $f$ is then pointwise bounded, but I'm not sure if that means I can find some $M$ such that $f(x) \le M$ for all $x$.
For the reverse implication, I haven't come up with anything useful - I have been trying to show that the sequence of partial sums, $\sum^m_{n=1}\mu(A_n)$, is bounded, but I'm not sure how to do so.

REPLY [8 votes]: Define $A_k=\{x:f(x)\geq k\}$ (as you had done so) and $B_k=\{x:f(x)\in[k,k+1)\}$. The $B_k$ are pair-wise disjoint. We have $\displaystyle X=\bigcup_{k=0}^\infty B_k$. Also note that $\displaystyle A_n=\bigcup_{k=n}^\infty B_k$. This gives us $\displaystyle \mu(X)=\sum_{k=0}^\infty \mu(B_k)$ and $\displaystyle \mu(A_n)=\sum_{k=n}^\infty \mu(B_k)$.
Assume non-negative $f:X\rightarrow \Bbb R$ is integrable, then 
$$\infty>\int_X f d\mu \geq \sum_{k=1}^\infty k\mu(B_k)= \sum_{k=1}^\infty \mu(A_k). $$
Writing out $\mu(B_k)$ each $k$ times in a list/grid and rearranging the sum appropriately shows the last equality. This gives one direction. 
For the other direction, assume $\displaystyle \sum_{k=1}^\infty \mu(A_k)<\infty$. 
Since $f$ is measurable and bounded on each $B_k$, it is integrable on each $B_k$ (prove this), and we have
$$
\begin{aligned}
\int_{X} f d\mu&=\lim_{N\rightarrow\infty}\sum_{k=0}^N \int_{B_k} f d\mu\\
&\leq \lim_{N\rightarrow\infty}\sum_{k=0}^N (k+1)\mu(B_k) \\
&=\mu(X)+\mu(A_1)+\mu(A_2)+\cdots<\infty
\end{aligned}
$$
Again, writing out $\mu(B_k)$ each $k+1$ times in a list/grid and rearranging the sum appropriately shows the last equality.