added greedy algorithm