Pagini recente » Cod sursa (job #1087752) | Cod sursa (job #830020) | Cod sursa (job #2275326) | Cod sursa (job #1513174) | Cod sursa (job #2221651)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
freopen("ssm.in", "r", stdin);
freopen("ssm.out", "w", stdout);
int n;
scanf("%d", &n);
int allnegative = 1;
int left = 1, right = 1, sum = 0, lmax, rmax, max = 1 << 31;
for(int i = 1; i <= n; ++i)
{
int a;
scanf("%d", &a);
if(a > 0)
allnegative = 0;
if(allnegative && max < a)
{
max = a;
lmax = i;
rmax = i;
}
if(sum + a >= 0)
{
right = i;
sum += a;
if(max < sum)
{
max = sum;
lmax = left;
rmax = right;
}
}
else
{
left = i + 1;
sum = 0;
}
}
printf("%d %d %d", max, lmax, rmax);
return 0;
}