wa in GSS4 spoj

problem = SPOJ.com - Problem GSS4
my soln = fyqxJX - Online C++ Compiler & Debugging Tool - Ideone.com

Please someone help why am I getting wrong answer

I created 2 binary indexed tree one for sum
and other for finding the next index that is not one