题目地址:点击打开链接 思路:水题 AC代码: #include iostream #include cstdio #include cstdlib #include algorithm #include queue #include stack #include map #include cstring #include climits #include cmath usin
题目地址:点击打开链接
思路:水题
AC代码:
#include <iostream>#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;
int a[10001];
int main()
{
int n,i,sum,max1,start,end1,temp,flag;
while(scanf("%d",&n) && n)
{
flag=0;
sum=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]>=0)
{
flag=1;
break;
}
}
max1=a[0];
temp=0;
start=0;
end1=0;
for(i=0;i<n;i++)
{
sum += a[i];
if(sum > max1)
{
max1 = sum;
start = temp;
end1 = i;
}
if(sum<0)
{
sum = 0;
temp = i + 1;
}
}
if(flag)
{
printf("%d %d %d\n",max1,a[start],a[end1]);
}
else
{
printf("0 %d %d\n",a[0],a[n-1]);
}
}
return 0;
}