Maximum Circular Sum prob

#include
#include
#include

using namespace std;

int main() {
int t;
int res;
cin>>t;
for(int tc=0; tc<t; tc++) {
int n;
int cs=0,ms=0;
cin>>n;
int arr[n];
for(int i=0; i<n; i++)
{
cin>>arr[i];
}

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

// cout<<ms<<endl;
// for minimum subarray sum
cs=0, ms=0;
int cumSum=0;
for(int i=0; i<n; i++)
{
cumSum+= arr[i];
arr[i]= -arr[i];
cs=cs+ arr[i];
if(cs<0)
{
cs=0;
}
ms= max(cs, ms);
}
// cout<<cumSum<<endl;
// cout<<ms;
int candidate2=cumSum-(-ms);
res= max(candidate1, candidate2);

}

cout<<res;
return 0;
}
wrong- answer .


I have made a very slight change, you were not using endl after every test case and also you were printing the value of last res, like after the test cases end… you print res, instead it need to be printed for every test case instead…