#include <bits/stdc++.h>
using namespace std;
const int maxn = 50005;
int num = 0;
struct node
{
int *elem;
int len;
};
void Creatlist(struct node &list, int n)
{
list.elem=new int[maxn];
if(!list.elem)
exit(OVERFLOW);
for(int i=1; i<=n; i++)
{
scanf("%d",&list.elem[i]);
list.len++;
}
}
int get_ans(struct node &list, int l, int r)
{
num ++;
int sum1, sum2, sum3, sum4, mav3, mav4;
if(l == r)
{
if(list.elem[l] < 0)
return 0;
else
return list.elem[l];
}
int m = (l + r) / 2;
sum1 = get_ans(list, l, m);
sum2 = get_ans(list,m + 1, r);
sum3 = sum4 = 0;
mav3 = mav4 = 0;
for(int i = m; i >= l; i --)
{
sum3 += list.elem[i];
mav3 = max(mav3,sum3);
}
for(int i = m + 1; i <= r; i ++)
{
sum4 += list.elem[i];
mav4 = max(mav4,sum4);
}
int ans = 0;
ans = max(sum1, sum2);
ans = max(ans, mav3 + mav4);
return ans;
}
int main()
{
int n;
struct node list;
scanf("%d",&n);
Creatlist(list, n);
num = 0;
int ans = get_ans(list,1,n);
printf("%d %d\n", ans, num);
return 0;
}
标签:3664,子段,int,list,elem,SDUT,ans,mav3,mav4 From: https://blog.51cto.com/u_15965659/6056622