finished the greedy time algorithm