Test cases not working not even the sample test cases

include
using namespace std;
int main() {
int a[100],b[100],c[100];
int i,n,max1=0,max2=0,wc=0,min;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
if(a[i]>=max1)
{
max1=a[i];
b[i]=max1;
}
}

for(i=n-1;i>=0;i--)
{
	if(a[i]>=max2)
	{
	max2=a[i];
	c[i]=max2;
	}
}
for(i=0;i<n;i++)
{
	if(b[i]<c[i])
	min=b[i];
	else
	min=c[i];
	wc=wc+min-a[i];
}
cout<<wc;


return 0;

}

The approach you are trying to use in your code is wrong… Use the approach as,

int leftmost[100];
int rightmost[100];
int value[100];
int sum=0;
for(int i=0;i<n;i++)
{
leftmost[i]=max(ar[i],leftmost[i-1]);
}
rightmost[n-1]=ar[n-1];
for(int i=n-2;i>=0;i–)
{
rightmost[i]=max(ar[i],rightmost[i+1]);
}
for(int i=0;i<n;i++)
{
value[i]=min(leftmost[i],rightmost[i])-ar[i];
}
for(int i=0;i<n;i++)
{
sum=sum+value[i];
}

You can also refer to the video given in your online lecture as,