Rain Water Harvesting Problem

Hi! My code is failing for multiple test cases. Please let me know what all things should be added into the code.

hello @rachitbansal2500
the issue is with ur size of all the arrays,
check maximum value of n possible and declare size of every array greater than that.

Can you please correct it? I am unable to.

Hey! So you just made sure that the array is the same size as the array? Why wasn’t the code working if I was declaring the array as arr[1000000] because the constraint was already mentioned. I even changed the datatype of n to long long int. Can you please explain? How to avoid such errors in the future?

declare ur array as global variable and then it should work,
to avoid such errors,
never declare array like int arr[1000 000].
first read n (size of array ) and then use this n to declare ur array size.
something like.
int n;
cin>>n;
int arr[n];

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.