Initial implementation of greedy algorithm