Max subarray sum

ehy is this showing time limit exceeding?

#include using namespace std; int main() { int t; cin>>t; for(int i=0;i<t;i++){ int n; cin>>n; int a[1000]; int cs=0; int ms=0; 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; } }

Pls send your code by saving on ide so that I could check it…

In line no 10 of your code, take a[n], instead of a[1000] and then try to submit your code.

1 Like

yeah it worked thanks!!!