原題鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1231
#include<stdio.h>
#include<stdlib.h>
int n,i,a[10005],b,thisSum,thisi,thisj,sum;
int tempi,tempj;
bool flag;
int main()
{
while(~scanf("%d",&n))
{
if(n == 0) break;
b = 0,thisSum = 0,sum = -1,thisi = 0,thisj = 0;
tempi = 0,tempj = 0;
flag = true;
for(i = 0; i < n; i++)
{
scanf("%d",&a[i]);
if(a[i] >= 0) flag = false;
}
if(flag)
{
printf("%d %d %d\n",0,a[0],a[n - 1]);
continue;
}
for(i = 0; i < n; i++)
{
if(b > 0)
b += a[i];
else b = a[i],tempi = i;
if(b > sum)
{
sum = b;
thisi = tempi;
thisj = i;
}
}
printf("%d %d %d\n",sum,a[thisi],a[thisj]);
}
}