greedy theorem