Rain Water Harvesting

I am getting run time error in 2-3 test-cases…
Please tell what Should I do

you should make maximum prefix and suffix arrays

I haven’t understood on how to make max prefix and suffix arrays…

pref[0]=a[0];
for(int i=1;i<n;i++)
pref[i]=max(pref[i-1],a[i]);

Similarly for suffix but from n-1 to 0.