Finding ways to choose numbers

finding ways of choosing one number each from m bags(each bag contains “l” numbers) such that sum of picked number is between X and Y .X < Y.
I want to know how to solve it iteratively.
Tnx in advance.