和上一题一样,只不过变为数组。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 10005;
int main()
{
// freopen("in.txt", "r", stdin);
int K, i, maxx, pro, fir, endd, s, a;
int num[N];
while(~scanf("%d", &K) && K)
{
pro = 1;
maxx = -1001;
s = 0;
memset(num, 0, sizeof(num));
for(i = 1; i <= K; i ++)
{
scanf("%d", &num[i]);
s += num[i];
if(s > maxx)
{
fir = num[pro];
endd = num[i];
maxx = s;
}
if(s < 0)
{
s = 0;
pro = i + 1;
}
}
if(maxx < 0) { maxx = 0; fir = num[1]; endd = num[K]; }
printf("%d %d %d\n", maxx, fir, endd);
}
return 0;
}