Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

38 lines
818 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}