I have several task groups, each group is a chain of tasks, groups are independent of each other. Tasks within a group can only be processed in the order that is determined by the chain of that group.
Each task has an identifier and a cost. Tasks are atomic, they can only be completed immediately by investing in them units of time equal to their cost (not solving half the problem). At the beginning of each step, mtime units are available .
I want to check whether it is possible to complete all tasks within a given number of steps d.
Here are some photos to clarify the situation, each task is a 2-tuple (ID, Cost), tasks in chains can be solved only from left to right.
Here is a graphical example of 6 tasks arranged in 3 groups:

Let's say that m = 5(5 units of time are available at each step) and d = 4(we want to check whether all tasks can be completed in 4 steps). Possible soul:

Another possible solution:

An invalid solution would be (it completes all the tasks in 5 steps, we said that the limit is 4):

My question is:
For this:
- tasks that are grouped into groups
- number of time units
mavailable at each step - and a few steps
dthat are allowed
determine whether it is possible to solve all the tasks in steps d, if so, print a possible sequence (task identifiers) in which tasks can be solved so that the steps are performed <= d.
My current approach:
. , A ( , , ) B ( A, <= d , <= d). B , , , ( ), B ( , ). , > d ( ) ( deques , <= d).
PseudoJavaish code:
findValidSequence (ArrayList<Deque> groups, int[] sequence, int steps) {
if (steps > d)
if (groups.isEmpty())
Set A = getAllTasksSolvableDuringCurrentStep();
Set B = determineAllTheOptionsForTheNextStep(A);
for (each element in B)
findValidSequence(groups.remove(B), sequence.setSolvedTasks(B), steps+1);
}
, , , ?
:
, (m n ).