What is the error in this code please explain my error

#include
using namespace std;
int main() {
int a[1000],i,k,j,n,testcases;
int currentsum=0;
int maxsum=0;
cin>>testcases;
cin>>n;

for(int l=0;l<testcases;l++)
{   for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=i;j<n;j++)
        {
            currentsum=0;
            for(k=i;k<j;k++)
            {
                currentsum=currentsum+a[k];}
                //cout<<currentsum<<endl;
                if(currentsum>maxsum)
                {
                    maxsum=currentsum;
                }
    }

}
cout<<maxsum<<endl;}
return 0;
}

Your code has a time complexity of O(n^3). And this is not acceptable at all. For finding the maximum subarray sum, we use Kadane’s Algorithm which runs in O(n) time complexity.


Read this article.

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.