First version of Greedy Algorithm