new greedy algorithm