What is wrong in my code?

My code works fine for the test case provided. Then why is it showing wrong answer and runtime error for the other test cases? What is wrong?

@Mac2503
Your logic is correct but check the input constraints n is upto 10^6 but your array a[], inc[], decr[] is of size 10^3 which would give segmentation fault for n>10^3. So increase size of these array to 10^6.
Also make these array global. Declare them again and again for each testcase would required lot of memory and give error.

@Mac2503


Here is the updated code. please check

@Mac2503
As I can see you got 100 point for this question. please mark it as resolved.