Run error constantly appearing

whenever i run my code in my ide, it works fine and when I run it in cb ide, it works fine there too but as soon as I hit the submit button it shows “run error”

#include

using namespace std;

int main(){
int testCases, a[1000], n, output[100] = {0}, j = 0;

cin>>testCases;

while(testCases>0){
    
    cin>>n;
    int currentSum = 0;
    int ms = 0;
    

    for(int i = 0; i<n; i++){
        cin>>a[i];
    }

    for(int i = 0; i<n; i++){
        currentSum = currentSum + a[i];
        if(currentSum < 0){
            currentSum = 0;
        }
        ms = max(currentSum, ms);
        
    }

    output[j] = ms;
    


    j++;
    testCases--;
}



for(int i = 0; i<j; i++){
        cout<<output[i]<<endl;
    }
return 0;

}

Hey @arjun.12narang please share your code using ide.codingblocks.com, if you don’t know how to do that. You can ask me that too.

Have debugged your code here, and have added comments too, Now it’s giving 100% result

Why does it matter if i put int ms = 0; rather than int ms =INT_MIN ?

INT_MIN will work when you will have an array of all negative elements

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.