In most recipes, certain tasks have to be done before others. For each task, if we are given a list of other tasks that it depends on, then it is relatively straightforward to come up with a schedule of tasks that satisfies the dependencies and produces a stunning dish. Many of us know that this can be solved by some algorithm called toplogical sort.
But life is not so easy sometimes. For example, here is a recipe for making pizza dough:
1.Mix the yeast with warm water, wait for 5 to 10 minutes.
2.Mix the the remaining ingredients 7 to 9 minutes.
3.Mix the yeast and the remaining ingredients together for 10 to 15 minutes.
4.Wait 90 to 120 minutes for the dough to rise.
5.Punch the dough and let it rest for 10 to 15 minutes.
6.Roll the dough.
In this case, tasks 1 and 2 may be scheduled after the first minute (we always spend the first minute to read the recipe and come up with a plan). The earliest task 3 may be started is at 8 minutes, and task 4 may start at 18 minutes after the start, and so on. This recipe is relatively simple, but if some tasks have many dependent tasks then scheduling can become unmanageable. Sometimes, the recipe may in fact be impossible to execute. For example, consider the following abstract recipe:
1.task 1
2.after task 1 but within 2 minutes of it, do task 2
3.at least 3 minutes after task 2 but within 2 minutes of task 1, do task 3
In this problem, you are given a number of tasks. Some tasks are related to another based on their starting times. You are asked to assign a starting time to each task to satisfy all constraints if possible, or report that no valid schedule is possible.