Finished greedy algo