Modified greedy algorithm implemented.