#include<iostream>
using namespace std;
int max_sum(int a[],int n,int*best_i,int *best_j)
{
int i,j,k,this_sum;
int sum=0;
*best_i=0,*best_j=0;
for(int i=0;i<n;i++)
{
this_sum=0;
for(j=i;j<n;j++)
{
this_sum+=a[j];
if(this_sum>sum)
{
sum=this_sum;
*best_i=i;
*best_j=j;
}
}
}
return sum;
}
int main()
{
int n,i,j;
cout<<"输入整数个数:"<<endl;
cin>>n;
int a[n];
cout<<"输入数组:"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
int c=max_sum(a,n,&i,&j);
cout<<"最大字段和为:"<<" "<<c<<endl;
cout<<"起始位置:"<<i<<" "<<"结束位置:"<<j<<endl;
return 0;
}