Maximum circular sum problem

my output is coming correct on ide but showing wrong ans on hackerblocks

#include
#include
using namespace std;
int main() {
int t;
cin>>t;
int i,j,k,l;
for(i=0;i<t;i++){
int n;
cin>>n;
int a[1000];
for(j=0;j<n;j++)
cin>>a[j];
int flag=0;
int cs=0;
int ms=0;
for(j=0;j<n,flag!=2;j++){
if(flag==1&&j==n-1){
flag++;
continue;
}

  cs=cs+a[j];
  if(cs<0)
  cs=0;
  ms=max(cs,ms);
  if (j==n-1)
  {
    j=-1;
    flag++;
  }
  
}
cout<<ms;

}

return 0;

}

Heyy Pratika !!! your logic is wrong somewhere as you can check for this test case .
1
5
-1 2 -1 2 3
Actually there is no need to compute so many things , you just need to find the minimum subarray sum and your maximum circular subarray sum will be Total array sum - Minimum Subarray sum .
It sounds obvious , isn’t it ?