Rain water harvesting

sir my code is working fine here is the code

but when i try test case no 7 it show error??why? on normal cases the code gives right output even in the ediitoral i tried runing with other test cases it works but for test case 7 editorial code is also showing error why ? for test case 7

look at
Constraints
1 <= N <= 10^6
they are large

in your code size of array is 10^6 but size of left and right array is 10^5 only that is why it is giving wrong ans

but when you make size of left and right array 10^6 it will give run error in all testcases
because code is not optimised an required lot of memory and time

try to optimise your code

Modified Code

sit than this modified code is also not working even editorial soltution is giving compilation error when can i find ??? opimized solution?

Please check again
Modified Code is passing all testcases