TITLE: How to fill up $(0,1)$ with disjoint closed intervals all total measure one
QUESTION [8 upvotes]: This is a problem which was proposed, but not chosen, in a Mathematics competition for University students not long ago, and its solution is missing:

Let $\sum_{n=1}^\infty a_n=1$, where $a_n>0$, for all $n\in\mathbb N$.
  Is it possible to find pairwise disjoint closed intervals
  $I_n=[c_n,d_n]\subset (0,1)$, with $d_n-c_n=a_n$?

EDIT I. The answer is yes (see the Answer that follows). The interesting thing though is that $(0,1)\smallsetminus\bigcup_{n\in\mathbb N}I_n$ in  nonempty. In particular, can you show that $$D=[0,1]\smallsetminus\bigcup_{n\in\mathbb N}I_n$$ is a Cantor-like set?
EDIT II. See a relevant article by Terry Tao.

REPLY [6 votes]: Choose $c_1=\sum_{k=1}^\infty a_{2k}$ and $d_1=1-\sum_{k=1}^\infty a_{2k+1}$. Iterate for the two remaining intervals and the two remaining sub-sums.