greedy algorithm update