The problem can be solved in time O(n log n) with an algorithm by
Garey, Johnson, Simons, Tarjan (1981). In this paper they first present a simpler algorithm running in time O(n2), which is implemented here.
The shaded area represent the regions computed by the algorithm in which it is forbidden to start a job, because otherwise it would be impossible to complete all jobs before their deadlines.