Output not coming correctly

#include
using namespace std;
int main()
{
int t;
cin>>t;
while(0<t<20)
{
int n;
cin>>n;
int currentsum = 0;
int maxsum = 0;
int *arr = new int[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
//generating subarray
for(int j=0;j<n;j++)
{
for(int k=j;k<n;k++)
{
currentsum = 0;
for(int l=j;l<=k;l++)
{
currentsum += arr[k];
if(currentsum > maxsum)
{
maxsum = currentsum;
}
}
}
}
cout<<maxsum<<endl;

		t++;
}

}

Please save your code on ide.codingblocks.com and then share its link.

Follow the Kadane algo. It is of O(n) complexity. There is already a lecture video. Please refer that and try again.

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.