Rain water harvesting , two test case failling

#include
using namespace std;
void leftmax(int arr[],int left[],int size)
{
int max =0;
for(int i=size-1;i>=0;i–)
{
max = arr[i];
for(int j=i-1;j>0;j–)
{
if(max<arr[j])
max = arr[j];
}
left[i] = max;
}
}
void rightmax(int arr[],int right[],int size)
{
int max =0;
for(int i=0;i<size;i++)
{
max = arr[i];
for(int j=i+1;j<size;j++)
{
if(max<arr[j])
max = arr[j];
}
right[i] = max;
}
}
int main() {
int size;
cin>>size;
int arr[size];
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
int left[size],right[size];
leftmax(arr,left,size);
rightmax(arr,right,size);
int total=0;
for(int i=0;i<size;i++)
{
/* total +=min(left[i],right[i])-arr[i];*/
if(min(left[i],right[i])>0)
{
total = total + min(left[i],right[i])-arr[i];
}
}
cout<<total;
return 0;
}

You aren’t using any library so hiw is thus progrqm workibg

And right printing should be started from right side

For filling elements from left side start with indexi=1 and print max if left[i-1] and arr[i] and right from i-2