Pagini recente » Cod sursa (job #2498436) | Cod sursa (job #2730474) | Cod sursa (job #1913561) | Cod sursa (job #2778036) | Cod sursa (job #2391733)
#include <bits/stdc++.h>
using namespace std;
long long y, n, s, i, p1, p2, ct, nrmax = LLONG_MIN, pmax, x, maxx = LLONG_MIN;
int main()
{
ifstream f("ssm.in");
ofstream g("ssm.out");
f >> n;
for(i = 1; i <= n; i++)
{
ct++;
f >> y;
s = s + y;
if(y > nrmax) nrmax = y, pmax = i;
if(s > maxx) maxx = s, p2 = i, x = ct;
if(s < 0) s = 0, ct = 0;
}
if(maxx < 0)
{
g << nrmax << " " << pmax << " " << pmax;
return 0;
}
g << maxx << " " << p2 - x + 1 << " " << p2;
return 0;
}