finished greedy algorithm
~~ not performing well though