SIGSEGV error in the problem Break the String

The logic I have used is that sc keeps track of the imbalance in the string, and whenever it is about to cross k, the next position gets added to pos and div (the quotient when k divides the imbalance) increases. If the imbalance decreases to under k, we remove the last position added and decrease div. The ans has a string with ‘1’ in all the stored positions in pos and position 0, which is then printed.

I am unable to understand why this program is giving SIGSEGV error, would appreciate any advice on this matter