Maximum subarray sum in problem

#include
using namespace std;

int maxsum(int *arr,long long int n)
{
long long int cs=arr[0];
long long int ms=0;

for(int i=1;i<n;i++)
{
	if(cs<0)
	 cs=0;
	 
	else
	{
		cs=cs+arr[i];
		ms=max(cs,ms);
	}
}

return ms;

}

int main()
{
int t;
cin>>t;
while(t–)
{
long long int n;
cin>>n;

	int arr[n];
	
	for(int i=0;i<n;i++)
	  cin>>arr[i];
	  
	long long int ans=maxsum(arr,n);
	cout<<ans<<endl;
}
return 0;

}

//plzz check my code

@ynikhil1999
You should change the return type of your function to long long int as well since even though your answer is computed in the function as long long int , it being returned as int would change its value.

Also there is no else part in Kadane’s Algo .
This is how it should be :
long long int maxsum(long long int *arr,long long int n)
{
long long int cs= 0;
long long int ms=0;

for(int i=0;i<n;i++)
{

cs=cs+arr[i];

if(cs<0)
 cs=0;
 
ms=max(cs,ms);

}

return ms;
}

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.