code force problem, trying the greedy method.