Energy loss of heavy quarks and B and D meson spectra in PbPb collisions at LHC energies