Given an arbitrary number of ordered lists
List<int> list1 = new List<int> {1, 1, 2};
List<int> list2 = new List<int> {1, 2, 3, 4};
List<int> list3 = new List<int> {1, 2};
List<int> listN = new List<int> {....,....};
I want to find the combinations of the lists such that sum of each combination are found in ascending order. For example,
{1, 1, 1} = 3, where {1 (1st element of list1), 1 (1st element of list2), 1 (1st element of list3)}
{1, 1, 1} = 3, where {1 (2nd element of list1), 1 (1st element of list2, 1 (1st element of list3)}
{1, 2, 1} = 4
{1, 1, 2} = 4
{2, 1, 1} = 4
...
The reason for finding the sum in ascending order is so that I have the option of calculating just the first M combinations (e.g. M = 5 above).
My current thinking is to somehow extend finding a combination of all lists, as discussed in Combination of List<List<int>>, by starting with a small subset of the list where the difference between the current and next element is 0, e.g.
List<int> tempList1 = new List<int> {1, 1};
List<int> tempList2 = new List<int> {1};
List<int> tempList3 = new List<int> {1};
and finding all combinations, then adding to the list the next element with the smallest difference
List<int> tempList1 = new List<int> {1, 1, 2};
List<int> tempList2 = new List<int> {1, 2};
List<int> tempList3 = new List<int> {1, 2};
and building the solution set from there.
Is this possible, and is there a better way to do this?