Max circular subarray

#include
using namespace std;

int main(){
int t;
cin>>t;
for(int z=1;z<=t;z++){
int cs=0,ms=0,cs1=0,ms1=0,ms2=0;
int n;
cin>>n;
int arr1[n];
int arr2[n];
for(int i=1;i<=n;i++)
{
cin>>arr1[i];
}
for(int i=1;i<=n;i++){
cs=cs+arr1[i];
cs = cs<=0?0:cs;
ms=max(ms,cs);
}
int cad1;
cad1=ms;
for(int i=1;i<=n;i++)
{
arr2[i]=-arr1[i];
}

for(int i=1;i<=n;i++){
cs1=cs1+arr2[i];
cs1 = cs1<=0?0:cs1;
ms1=max(ms1,cs1);
}
int cad2=0;
cad2=(cs-(-ms1)) ;
ms2=max(cad1,cad2);
cout<<(ms2);

return 0;}}
what is wrong in this code testcases are not passing

please save your code on the online ide

first of all you had put return 0 inside the for loop for the test cases due to which only one test case was working and an endl statement was missing

then consider your code for the following test cases
9
8
-1 40 -14 7 6 5 -4 -1
8
10 -3 -4 7 6 5 -4 -1
7
8 -8 9 -9 10 -11 12
9
11 10 -20 5 -3 -5 8 -13 10
100
81 13 -18 9 40 -6 47 -14 92 77 20 96 70 85 -1 10 97 56 35 48 33 39 63 -5 79 41 -13 32 -11 -4 43 5 -20 8 24 -10 61 98 100 -16 66 86 88 89 -3 25 58 37 42 51 36 -19 22 60 23 93 76 94 50 15 46 -12 18 -8 64 62 12 6 44 2 28 27 3 95 38 59 4 91 -17 1 45 87 0 -15 53 74 99 65 78 84 57 -2 17 -9 7 29 11 30 52 -7
100
87 24 1 11 83 -3 86 -19 67 80 13 70 84 -6 20 92 81 35 63 -12 41 46 39 27 57 12 52 30 38 -2 21 77 72 9 25 54 29 75 73 85 -14 76 60 82 6 49 40 89 32 59 74 26 97 55 47 66 0 15 7 64 -1 28 98 100 48 33 -5 5 -18 51 56 78 58 43 -4 22 14 -20 91 -13 99 2 -8 -10 94 36 -15 -11 37 3 65 34 62 8 50 16 31 45 -9 90
100
41 66 91 -10 87 28 31 35 69 79 53 84 46 98 56 94 7 20 37 12 27 -11 -17 6 80 92 89 100 47 5 21 11 8 22 23 64 50 55 -15 85 51 45 82 48 71 15 -1 26 43 18 57 14 -5 72 30 68 67 -14 42 60 34 97 83 19 9 29 -4 -3 76 -20 88 -9 62 16 0 -7 73 -6 99 25 81 36 40 32 77 44 17 3 52 58 74 86 -8 93 95 54 61 63 96 49
100
32 -16 -6 14 86 66 69 28 88 87 11 0 7 3 37 60 62 -19 79 43 12 73 70 19 44 33 85 71 34 18 -15 54 -3 -12 21 83 52 91 75 81 95 4 49 63 82 58 72 36 -11 84 78 15 6 -4 -20 25 53 13 5 99 2 94 -2 89 26 8 55 -17 29 -5 9 31 45 -9 74 97 90 24 10 48 27 77 65 61 20 93 41 23 92 40 80 57 68 76 22 98 56 -7 -1 64
100
14 -9 -3 82 79 67 25 78 10 38 22 -20 28 84 -15 89 98 26 57 1 6 63 92 4 52 5 46 54 -2 3 74 -12 -13 100 55 24 81 60 35 -11 -6 -4 32 -14 77 37 45 34 33 96 97 27 48 36 -16 66 -18 -19 43 51 29 21 64 12 -17 18 19 71 91 41 -8 2 -5 44 86 94 7 47 31 53 -7 16 68 15 65 88 42 93 83 40 50 58 49 -1 80 17 13 30 85 99

expected output:
53
23
23
38
3711
3956
4347
4193
3832

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.