Greedy algorithm.