Greedy algorithm