Maximum length bitonic array

Segmentation fault; core dumped

#include

using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
int inc[n], dec[n];
inc[0]=1;
dec[n-1]=1;
for(int i=1; i<n; i++)
{
inc[i]=(a[i]>= a[i-1])?inc[i-1]+1:1;
}
for(int i=n-2; i>=0; i–)
{
dec[i]= (a[i]>=a[i+1])?dec[i+1]+1:1;
}
int max=inc[0]+dec[0]-1;
for(int i=0; i<n; i++)
{
if(inc[i]+dec[i]-1>max)
{
max=inc[i]+dec[i]-1;
}
}
cout<<max<<endl;
}
return 0;
}

No , I just submitted your code, it passed all the testcases.

but it is not working in ths ide. it says segmentation fault in line no 4 ( core dumped)

There must be some issue with your input format, the code works fine

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.