Unexpected output

why is the code below not taking sum in circular for,
i feel it is logically correct.
please check.

#include
#include
using namespace std;
int main()
{
int n;
cin>>n;
int brr[1000];
for(int i = 0; i<n; i++)
{
int New;
int arr[New+1000];
int cs=0;
int ms=0;
int p=0;
int n=1;

    cin>>New;
    for(int j=0; j<New; j++)
    {
        cin>>arr[j];

    }
    cs = arr[0];
    while(n!=p )
    {
        cs = cs +arr[n];
        if(cs<0)
        {
            cs = 0;
            p = n+1;
        }
        n=n+1;
        if(n=New-1)
        {
            cs =cs+arr[n];
            n=0;
        }
        ms =max(cs,ms);

    }

    brr[i]=ms;





}
for(int i=0; i<n; i++)
{
    cout<<brr[i]<<endl;
}


return 0;

}

Hey @saurabh66 your algorithm doesn’t seems to work as you may exit the loop as soon as you reach a point where cs<0 and n!=New-1 (as p=n=n+1)
also if check

should be == and not =.
Try to think Kadane’s and how some modification can be applied to circular array!

thanks @mayankA47 sir!
i used kadane’s for the next attempt and submitted with a success.

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.