The dynamical Borel-Cantelli lemma and the waiting time problems