https://blog.csdn.net/weixin_37605770/article/details/78277457
#include<bits/stdc++.h>
using namespace std;
int _count=0;
int maxx(int a[],int left,int right)
{
_count++;
int sum,i,ret,mid,leftmax,rightmax,left_max,right_max;
if(left==right)
return a[left]>0?a[left]:0;
mid = (left+right)/2;
leftmax = maxx(a,left,mid);
rightmax = maxx(a,mid+1,right);
sum = left_max = 0;
for(i=mid;i>=left;i--)
{
sum+=a[i];
left_max = max(left_max,sum);
}
sum = right_max = 0;
for(i=mid+1;i<=right;i++)
{
sum+=a[i];
right_max = max(right_max,sum);
}
ret = left_max+right_max;
ret = max(ret,max(leftmax,rightmax));
return ret;
}
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin>>n;
int a[100000];
for(int j=0;j<n;j++)
cin>>a[j];
int M = maxx(a,0,n-1);
cout<<M<<" "<<_count<<endl;
return 0;
}