I could not find a test case where it fails, but i can say my code is pretty much like except for some details which i think are the diference, why dont you try breaking the cycle when maxi is modified? i think that maxi could be modifyed again, and that could give you WA, but i'm not totally sure.