Production of charged pions, kaons, and (anti-)protons in Pb-Pb and inelastic pp collisions at root s(NN)=5.02 TeV