I solved the problem in 0(n) but it didnt pass all the test cases

#include
using namespace std;

int main() {
int n;
cin>>n;
long long int a[n],l[n],r[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
l[0]=a[0];
for(int i=1;i<n;i++)
{
l[i]=max(a[i],l[i-1]);
}
r[n-1]=a[n-1];
for(int i=n-2;i>=0;i–)
{
r[i]=max(a[i],r[i+1]);
}
long long int s=0;
for(int i=1;i<n-1;i++)
{
long long int x=min(l[i-1],r[i+1]);
if(x>a[i]&&a[i]>=0)
s=s+(x-a[i]);
}
cout<<s<<"\n";
}

Hello @vibhubhatia0007 i have corrected your code:


it is passing every test case:
if you have any doubt you can ask here:
Happy Learning!!

int32_t main() is it to handle the long long int or what can you please explain it what does int32_t does

Hello @vibhubhatia0007 no no int32_t main is not for handling the long long int
as you can see that i have defined int as long long int type but a int int main cant be of the type long long int so we have to handle that .
that is the reason i have written int32_t .
i think it does not do anything more.
if you still have any doubt you can ask here:
Happy Learning!!

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.