Using extended TreeSet, still Time Limit Exceeded