标签:style blog http color strong os
6 1 -2 3 5 -1 2 5 6 -1 5 4 -7
10 14
解题:环形最大子序列和,跟这一题差不多
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long 10 using namespace std; 11 LL d[100010]; 12 int main() { 13 int n,i; 14 LL u,v,x,y,sum; 15 bool flag; 16 while(~scanf("%d",&n)) { 17 u = INT_MIN; 18 v = INT_MAX; 19 x = y = 0; 20 flag = false; 21 for(sum = i = 0; i < n; i++){ 22 scanf("%lld",d+i); 23 sum += d[i]; 24 if(d[i] >= 0) flag = true; 25 if(x >= 0) x += d[i]; 26 else x = d[i]; 27 u = max(u,x); 28 29 if(y <= 0) y += d[i]; 30 else y = d[i]; 31 v = min(v,y); 32 } 33 printf("%lld\n",flag?max(u,sum-v):0); 34 } 35 return 0; 36 }
NYOJ 745 首尾相连数组的最大子数组和,布布扣,bubuko.com
标签:style blog http color strong os
原文地址:http://www.cnblogs.com/crackpotisback/p/3849825.html