分解思想:dp[i]表示以a[i]结尾的最大连续序列和
最大序列和
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 1e10 + 10;
int main()
{
ll n;
while(cin>>n){
ll ans = -INF;
vector<ll>dp(n + 1, 0);
for(int i = 0; i < n; i ++ ) cin>>dp[i];
for(int i = 1; i < n; i ++ ){
dp[i] = max(dp[i], dp[i - 1] + dp[i]);
ans = max(ans, dp[i]);
}
cout<<ans<<endl;
}
return 0;
}