added greedy algorithm from Jia