Gas dynamics in the impulsive phase of solar flares. I. Thick-target heating by nonthermal electrons