I’m trying this question that should have been easily completed and all the outputs are coming out to be correct, but 4 cases are coming out to be wrong. I need to know whats going wrong with my code in this and some more questions
Dont know the mistake
Submission #4587910 - its showing run error in 4 cases, and 1 is correct
#include
#include
using namespace std;
int main() {
long long int n,a[100000],i,k,max=0,sum;
int t,j;
cin>>t;
for(j=0;j<t;j++)
{
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
max=a[0];
for(i=1;i<n;i++)
a[i]+=a[i-1];
for(i=0;i<n;i++)
{
for(k=i;k<n;k++)
{ if(i>0)
sum=a[k]-a[i-1];
else
sum=a[k];
if(sum>max)
max=sum;
}
}
cout<<max<<endl;
}
return 0;
}
i’m unable to share the link