Designing a greedy scheduling algorithm for two sets of non-mutually exclusive tasks
Nice exercise!

The usual strategy for designing greedy algorithms is to just brainstorm a bunch of different candidate strategies.  You're going to sort by some quantity; try some ideas for what that quantity might be -- maybe it is sorted by $a_i$, or by $b_i$, or by $a_i-b_i$, or something; try to come up with as many possibilities that make sense.  Then, for each candidate strategy, test whether it appears to be correct using the methods in How to prove greedy algorithm is correct.

Try that for a little while.  If you're still stuck, here's an extra hint (don't look until you've tried the above):


   See if you can figure out which of the $n$ items must come last.