Pagini recente » Cod sursa (job #3179613) | Cod sursa (job #3151397) | Cod sursa (job #2278609) | Cod sursa (job #407132) | Cod sursa (job #2651370)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("ssm.in");
ofstream out("ssm.out");
int n, i, x, antMax = 0, totalMax = 0, first = 0, last = 0;
in >> n;
for (i = 1; i <= n; i++)
{
in >> x;
if (x > 0)
{
//cout << "A crescut de la " << antMax << " cu: " << x << endl;
antMax += x;
}
else if (x)
{
if (antMax + x > 0)
{
//cout << "A crescut de la " << antMax << " cu: " << x << endl;
antMax += x;
}
else
{
//cout << "S-a restabilit la: " << i << endl;
first = i + 1;
antMax = 0;
}
}
if (antMax > totalMax)
{
totalMax = antMax;
last = i;
}
}
out << totalMax << " " << first << " " << last;
}