team split-SIGSEGV

for question team-split(http://www.codechef.com/problems/TMSLT), i am getting sigsegv error. can anyone help me in solving this problem.
my solution can be viewed here