Shows run error but sample inputs are working
Maximum-Subarray-Sum
Hi Rachit,
Share your code.
can anyone tell whats wrong with my code. The max sum is coming less than its actual value
#include
using namespace std;
int main() {
int t;
cin>>t;
int ms[t];
if(t>=1 && t<=20){
for(int i=0; i<t; i++){
int n;
cin>>n;
int a[100000];
if(n>=1 && n<=100000){
for(int j=0; j<n; j++){
int e=0;
cin>>e;
if(e>=-100000000 && e<=100000000){
a[i]=e;
}
}
}
int cs=0;
int maxs=0;
for(int j=0; j<n; j++){
cs=cs+a[j];
if(cs<0){
cs=0;
}
maxs=max(cs,maxs);
}
ms[i]=maxs;
}
}
for(int i=0; i<t; i++){
cout<<ms[i]<<endl;
}
return 0;
}