Maximum Circular Sum

#include
using namespace std;
int kadane(int a[],int n);
int kadane(int a[],int n)
{
int cs=0,ms=0,i;
for( i=0;i<n;i++)
{
cs=cs+a[i];
if(cs<0)
{
cs=0;
}
if(ms<cs)
{
ms=cs;
}

}
return ms;

}
int maxcircularsum(int a[],int n)
{
int max_kadane=0,wap_max=0,i;
max_kadane=kadane(a,n);
for(i=0;i<n;i++)
{
wap_max+=a[i];
a[i]=-a[i];
}
wap_max=wap_max+kadane(a,n);
return (wap_max>max_kadane)?wap_max:max_kadane;
}
int main() {
int t,n;
cin>>t;
while(t){
int a[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
t–;
cout<<maxcircularsum(a,n);
}
return 0;

}
the result of sample input is right but in test case it is showing wrong answer

Hi @17manishms
It is showing wrong ans becz for multiple test case your code is printing output in a single line … just include endl after cout<<maxcircularsum(a,n);

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.