test case 1 run error
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t!=0)
{
int ms=0;
int n;
int cs=0;
cin>>n;
int a[1000];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
cs=cs+a[i];
if(cs<0)
{
cs=0;
}
ms=max(cs,ms);
}
cout<<ms<<endl;
t=t-1;
}
}
Max subarray sum
hey @mishranavneet1710, check the constraints of the question they are very high so change the datatype from int to long long
i have made suggested changes still it is showing run error
hey @mishranavneet1710, you have made the size of array that it crosses the range of long long int, change it to n only,
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.