Please help me figure out error in my code

#include
using namespace std;
int main() {
int t;
cin>>t;
for (int j = 0; j < t; j++){
int n, a[1000], max_sum = 0, current_sum = 0;
cin>>n;
for (int i = 0; i < n; i++){
cin>>a[i];
}
for (int i = 0; i < 2 * n - 1; i++){
current_sum = current_sum + a[i % n];
if (current_sum < 0){
current_sum = 0;
}
if (current_sum > max_sum){
max_sum = current_sum;
}
}
cout<<max_sum<<endl;
}
return 0;
}

Plz send the code by saving on ide only.

Shubham I would suggest you to go through the online tutorial hint given under arrays ( 1-d ) on the maximum circular sum, and try to implement your code using that logic only since your current approach is not appropriate.

Please tell me on which testcase my algorithm is failing so that I could improve my method since I already knew what was taught in video so I was trying this self-formulated algo.

For eg : { -1, 40, -14, 7, 6, 5, -4, -1 }
Your Output : 37
Actual output : 23
( 7 + 6 + 5 - 4 -1 + 10 )

How 10 came in this sequence

Sry I typed input wrong as : 10, -3, -4, 7, 6, 5, -4, -1
Your output : 37
Actual output : 23
(7 + 6 + 5 - 4 -1 + 10)