Finite-energy spin fluctuations as a pairing glue in systems with coexisting electron and hole bands