Maximum circular sum

#include
using namespace std;
int currsum=0;
int maxsum=0;

int kadane(int a[],int n)
{
maxsum=0;
currsum=0;
for(int i=0;i<n;i++)

{
currsum += a[i];
if(maxsum<currsum)
{
maxsum=currsum;
}

   if (currsum<0)
   {
	   currsum=0;
   }

}
return maxsum;
}

int main() {

int t,n;
int a[100000];
cin>>t;
int cumsum=0;
for(int j=0;j<t;j++)
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
 int  x=kadane(a,n);
 	  for(int i=0;i<n;i++)
  {
	  cumsum+=a[i];
	  a[i]=-a[i];
  }

 int  y = kadane(a,n) + cumsum;


  cout<<max(x,y);

	
}
return 0;

}

@ramitkapoor print endl after every test case and if it do not works see the constraints if there is a integer overflow use long long instead of int
and if issue still exists let me know and if clear mark it as resolved and rate my experience

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.

No, the code still isn’t working. One mistake I can see is the code doesn’t work if all elements of the array are negative. Please send the corrected code