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.
Convince yourself that $$f(x)-1\leq \sum_{n=1}^\infty {\bf 1}_{(f\geq n)}(x)\leq f(x)$$ for all $x\in X$, then integrate with respect to $\mu$.