What's wrong int this

#include
using namespace std;
int main() {
int i,j,t,n,a[1000],ms,cs;
cin>>t;
while(t>0)
{
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
ms=0;
for(i=0;i<n;i++)
{
a[n+i]=a[i];
cs=0;
for(j=i;j<n+i;j++)
{
cs+=a[j];
if(cs<0)
{
cs=0;
}
ms=max(cs,ms);
}
}
cout<<ms;
t–;
}

return 0;

}

please paste the code at ide.codingblocks.com and share the link

Okay I did it for you


this is your code

Note that you need double sized array as you are appending the array to itself.
So, declare the array of size >= 2000 not 1000.

run err in some test cases has gone but it still showing wrong ans for all test cases

You forgot to do a newline after each testcase.

line 28 should be

cout << ms << '\n';

thank you for answering my stupidity, it is working fine now

1 Like

https://ide.codingblocks.com/s/317372 can you tell me in this code for finding large factorials what is wrong

Please post it as a new thread. In case you want me to be the one clearing your doubt, just PM me before posting it as doubt.

posted it on broken calculater

brother i have written my last doubt about piyush and magical park plz help its a separate thread

1 Like

as another doubt on this question

1 Like