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?
What is wrong in my code?
@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.