About ''rainwater trapping'' problem

please optimise this code if any kind of optimization is possible
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sum,totalsum=0;
cin>>n;
int b[100],left[100],right[100],LH[100],RH[100];
b[0]=0;
b[n+1]=0;
LH[0]=0;
RH[n+1]=0;
b[n+1]=0;
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
for(int i=1;i<=n;i++)
{
left[i]=max(b[i],b[i-1]);
LH[i]=max(left[i],LH[i-1]);
//cout<<LH[i]<<endl;
}
for(int i=n;i>=1;i–)
{
right[i]=max(b[i],b[i+1]);
RH[i]=max(right[i],RH[i+1]);
//cout<<RH[i]<<endl;
}
for(int i=1;i<=n-2;i++)
{
sum=min(LH[i],RH[i])-b[i];
totalsum=totalsum+sum;
}
cout<<“total stored water is “<<totalsum<<” units”;
}

Please share code via cb ide with indentation and comments

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.