Its not working for 1 testcase

TLE
here is the code:

@vketan182,
Updated Code Link.

where is the correction made??

@vketan182,
Global array.

how did it made a difference??

@vketan182,
Declare global arrays if you want to use large arrays, memory allocated to a specific function is less than the memory allocated to the whole program.