Maximum circular array problem

sir why the code is not running
#include
using namespace std;
int main()
{
int t;
cin>>t;
for(int x=0;x<t;x++)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int p[2n];
int k=0;
for(int i=0;i<n;i++)
{
p[k]=a[i];
k++;
}
for(int i=0;i<n;i++)
{
p[k]=a[i];
k++;
}
int cs=0;int ms=0;
for(int i=0;i<2
n;i++)
{
cs+=p[i];
if(cs<0)
{
cs=0;
}
ms=max(ms,cs);
}
cout<<ms<<endl;
}
}

hello @dreamerekta
your logic will fail.
for test cases like.
5
1 2 3 4 5 .

reason is at any time u can only consider atmost n continuos element but in ur algorithm it can be more than that.

for above test case ur alogrihtm will consider 10 elements in max i,e 1 + 2 + 3 + 4 + 5 + +1 + 2 + 3 + 4 +5.

refer this article for all vaid approaches of this problem -> https://leetcode.com/articles/maximum-sub-circular-subarray/

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.