Variational approach to a class of impulsive differential equations