# include<stdio.h> typedef struct { int a[55000]; }list; int x=0; int maxsum(list *p, int l, int r) { int i, s1=0, s2=0, maxl, maxr, mid, sum=0; x++; if(l==r) { if(p->a[l]>=0) sum=p->a[l]; else sum=0; } else { mid=(l+r)/2; maxl=maxsum(p, l, mid); maxr=maxsum(p, mid+1, r); int t=0; for(i=mid; i>=l; i--) { t += p->a[i]; if(s1<t) s1=t; } t=0; for(i=mid+1; i<=r; i++) { t += p->a[i]; if(s2<t) s2=t; } sum=s1+s2; if(sum<maxl) sum=maxl; if(sum<maxr) sum=maxr; } return sum; } int main() { int n, i, sum; list p; scanf("%d", &n); for(i=0; i<n; i++) { scanf("%d", &p.a[i]); } sum=maxsum(&p, 0, n-1); printf("%d %d\n", sum, x); return 0; }
转载于:https://www.cnblogs.com/mt123456/p/7563117.html