sum+=a[j];
if(sum>max&&sum>0)
max=sum;
}
}
if( max==a[0]&&max<0 )
max=0;
return max;
}*/
/*分而治之 O=logn
int MaxQSum3( int a[Max],int&x){
return DivideAndconquer(a,0,x-1);
}
int Max3(intA,intB,int C){
return A>B?A>C?A:C:B>C?B:C;
}
intDivideAndconquer(int a[Max],intleft,int right){ intLeftMax,RightMax,center;
if(right==left)
return 0;
center=(left+right)/2;
//“分”递归
LeftMax=DivideAndconquer(a,left,center);
RightMax=DivideAndconquer(a,center+1,right);
//"治"
intLeftBordMax=0,LeftBordSum=0;
for( inti=center;i>=left;i--){
LeftBordSum+=a[i];
if(LeftBordSum>LeftBordMax)
LeftBordMax=LeftBordSum;
}
intRightBordMax=0,RightBordSum=0;
for( inti=center+1;i<=right;i++){
RightBordSum+=a[i];
if(RightBordSum>RightBordMax)
RightBordMax=RightBordSum;
}
Max3( LeftMax,RightMax,RightBordMax+LeftBordMax);
return(LeftMax,RightMax,RightBordMax+LeftBordMax); }*/
/*在线处理 O=n 输出起点和终点*/
int MaxQSum4(int a[Max],int&x ,int&m,int&n){ inti,max,sum=0;
max=a[0];
m=a[0];
for(i=0;isum+=a[i];
if( sum>max ){
max=sum;
n=a[i];
}
else if(sum<0){
sum=0;
m=a[i+1];
}
}
return max;
}