Maximum circular sum

Output is correct but test case not passes :

#include
using namespace std;
int kadaneCir(long int a[],long int n)
{

int currSum=0,maxSum=0;

for(auto i=0;i<n;i++)
{
int temp=-a[i];
currSum=currSum+temp;
if(currSum<0)
{
currSum=0;
}
else
maxSum=max(currSum,maxSum);

}

maxSum=-maxSum;

int totalSum=0;
for(auto i=0;i<n;i++)
{
totalSum = totalSum+ a[i];

}
int finalSum=totalSum-maxSum;
return finalSum;
}
int kadane(long int a[],long int n){
int cs=0,ms=0;
for(auto i=0;i<n;i++)
{
cs=cs+a[i];
if(cs<0)
{
cs=0;
}
else{
ms=max(cs,ms);
}
}
return ms;
}
int main() {
int t;
cin>>t;
long int n;
cin>>n;
long int a[n]={0};
for(auto i=0;i<n;i++)
{
cin>>a[i];
}
for(auto i=0;i<t;i++)
{
int kad1=kadane(a,n);
// cout<<kad1<<endl;
int kad2=kadaneCir(a,n);
// cout<<kad2<<endl;
cout<<max(kad1,kad2);
}
return 0;

}

Hi. pls save ur code on ide and send… or u can refer this https://ide.codingblocks.com/s/604670

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.