hdu1231_HDUhdu1231_HDU_02View Code
#include"iostream"
using namespace std;
int main()
{
int n;
int a[10001];
int i;
int j=0;
while(cin>>n,n)
{
memset(a,0,sizeof(a));
int start=0,end=0;
int k=0;
int sum=0,Max=0;
int count=0;
int L=20000;
for(i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<0) count++;
if(a[i]==0&&i<L) L=i;
sum+=a[i];
if(sum>Max)
{
Max=sum;
start=k+1;
end=i+1;
}
if(sum<0)
{
k=i+1;
sum=0;
}
}
if(Max>0) cout<<Max<<" "<<a[start-1]<<" "<<a[end-1]<<endl;
else if(count!=n&&Max==0) cout<<Max<<" "<<a[L]<<" "<<a[L]<<endl;
else cout<<Max<<" "<<a[0]<<" "<<a[n-1]<<endl;
}
return 0;
}