Pagini recente » Cod sursa (job #390784) | Cod sursa (job #177666) | Cod sursa (job #1763815) | Cod sursa (job #2350487) | Cod sursa (job #2230121)
#include <bits/stdc++.h>
using namespace std;
int n, pozin, pozend, pozinmax, pozendmax, maxx, s, i, x;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f >> n;
pozin = 1;
for(i = 1;i <= n;i++)
{
f >> x;
if(x > 0)
{
s = s + x;
if(s > maxx)maxx = s, pozinmax = pozin, pozendmax = i;
}
else
{
s = s + x;
if(s < 0)s = 0, pozin = i + 1;
}
}
g << maxx << " " << pozinmax << " " << pozendmax;
return 0;
}