Cosmic-Ray Acceleration during the Impact of Shocks on Dense Clouds