CODEVS 1214 (greedy)