Greedy code works