Oh, here is the poster of the quesiton. I think I have found the reason. When we update ans
, we need to compare cnt1
and cnt2
. But before that, I have done cnt1 = (cnt1 % N + _nums1[p1] % N) % N
and cnt2 = (cnt2 % N + _nums2[p2] % N) % N
which changed how large they actually are.