finish greedy algorithm