Quark coalescence for charmed mesons in ultrarelativistic heavy-ion collisions