Run error in two of the test cases even when the answer match

why is there run time error even when i have reduced to code to its minimal structure. why? why? why you doing this to me?? i need answers…
Spent my whole night debugging this code but was unable to pass two of these testcases .
all the results match but these testcases still shows run error

@nik1898,
your logic is correct. Just don’t use the 2D array. For large test cases it is going out of memory space.

https://ide.codingblocks.com/s/233344 corrected code.

i have already applied this… and the code is reduced to only two loops

@nik1898,
Did you see the code I shared with you?