该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
int max(int a[],int left,int right);
int maxcross(int a[],int left,int right,int middle);
int xyzleft,xyzright;
int main()
{
int T;
int asd;
int num[100000];
scanf("%d",&T);
while(T--)
{
scanf("%d",&asd);
getchar();
int i;
for(i=0;i
{
scanf("%d",&num[i]);
getchar();
}
printf("%d %d %d\n",max(num,0,asd),xyzleft+1,xyzright+1);
printf("\n");
}
return 0;
}
int maxcross(int a[],int left,int right,int middle)
{
int sumleft=0,maxleft=-1001;
for(int i=middle;i>=left;i--)
{
sumleft+=a[i];
if(sumleft>maxleft)
{
maxleft=sumleft;
xyzleft=i;
}
}
int sumright=0,maxright=-1001;
for(int i=middle+1;i<=right;i++)
{
sumright+=a[i];
if(sumright>maxright)
{
maxright=sumright;
xyzright=i;
}
}
return maxright+maxleft;
}
int max(int a[],int left,int right)
{
int leftmax,rightmax,crossmax;
if(left==right)
{
xyzleft=xyzright=0;
return a[left];
}
else
{
int mid=(left+right)/2;
leftmax=max(a,left,mid);
rightmax=max(a,mid+1,right);
crossmax=maxcross(a,left,right,mid);
if(leftmax>rightmax&&leftmax>crossmax)
return leftmax;
else if(rightmax>leftmax&&rightmax>crossmax)
return rightmax;
else
return crossmax;
}
}