Pagini recente » Cod sursa (job #2919167) | Cod sursa (job #1162530) | Cod sursa (job #2562393) | Cod sursa (job #2563132) | Cod sursa (job #2447313)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int x, n, length{0}, last, first;
long long s{0}, smax{-900000000000};
int main()
{
fin >> n;
for(int i = 1; i <= n; i++)
{
fin >> x;
if(s + x < x)
{
length = 1;
s = x;
}
else
{
s += x;
length++;
if(s > smax){
smax = s;
last = i;
first = i - length + 1;
}
}
}
fout<<smax<<" "<<first<<" "<<last;
}