What's wrong with my submission of TWOFL(June Long)

I implemented the solution of Author given in the editorial, my implementation is same as of him, expect some minor changes in variable names but I keep failing a few test cases in Subtask-2 and 3 while Author’s solution passes.

My Solution : https://www.codechef.com/viewsolution/18880653
Author’s Solution : https://s3.amazonaws.com/codechef_shared/download/Solutions/JUNE18/setter/TWOFL.cpp

What am I doing wrong?