• + 0 comments

    The editorial is reasonably useful, but it's possible to find k in O(1) time (with O(max N) preprocessing, as in the editorial), giving an overall time of O(T + N) using a bit more math. The pattern isn't too hard to see, once you look for it.