标签:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1E5 + 10;
int a[maxn];ll dp[maxn];
int main(){
int n,flg = 1;
scanf("%d",&n);
for(int i = 0 ; i < n ; ++i){
scanf("%d",&a[i]);
if(a[i] >= 0) flg = 0;
}
if(flg){
printf("0\n");return 0;
}
memset(dp,0,sizeof(dp));
ll ans = 0;
dp[0] = a[0];
for(int i = 1 ; i < n ; ++i){
dp[i] = max((long long)a[i],dp[i - 1] + a[i]);
ans = max(dp[i] , ans);
}
printf("%lld\n",ans);
return 0;
}
[2016-05-09][51nod][1049 最大子段和]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/1de41c1b63b665fb5f9619195eca70ae.html