I have written a code which fails in two test cases and passes in 1 kindly tell the error
Code is
#include
#include
using namespace std;
int main()
{
int n,j,i,l,p;
cin>>n;
int a[n],v[n];
int g=0;
while(g<n)
{
cin>>a[g];
g++;
}
for(i=0;i<n;i++)
{
v[i]=a[i];
}
sort(a,a+n);
gā;
while(g>=0)
{
if(a[g]==a[g-1])
{
break;
}
else
{
gā;
}
}
for(i=0;i<n;i++)
{
if(v[i]==a[g])
{
break;
}
}
for(j=0;j<n;j++)
{
if(v[j]==a[g])
{
l=j;
}
}
int area=(l-i+1)*a[g];
for(p=i;p<=l;p++)
{
if(v[p]<a[g]|| v[p]==a[g])
{
int c=area-v[p];
area=c;
}
else
{
area=area-a[g];
}
}
cout<<area;
}