You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
781 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000001;
//https://blog.csdn.net/weixin_40295575/article/details/79627575
//program received signal sigsegv需要注意的问题
// 确实是栈溢出,大数组定义的时候尽量不要定义在函数体内
int a[MAXN];
int main() {
int n,i;
int ans;
int t;
cin>>n;
for(i=1; i<=n; i++)
cin>>a[i];
ans=a[1];
t=ans;
for(i=2; i<=n; i++) {
if(t>=0) {
cout<<"t>=0 before "<<"i="<<i<<" "<<"t="<<t<<" "<<"ans="<<ans<<endl;
t=t+a[i];
cout<<"t>=0 end "<<"i="<<i<<" "<<"t="<<t<<" "<<"ans="<<ans<<endl;
} else {
cout<<"t<0 before "<<"i="<<i<<" "<<"t="<<t<<" "<<"ans="<<ans<<endl;
t=a[i];
cout<<"t<0 end "<<"i="<<i<<" "<<"t="<<t<<" "<<"ans="<<ans<<endl;
}
cout<<endl;
if(t>ans) ans=t;
}
cout<<ans;
return 0;
}