Greedy algorithm for scheduler from topcoder tutorial