38 lines
818 B
C++
38 lines
818 B
C++
#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;
|
||
}
|
||
|
||
|