Cod sursa(job #1405381)
Utilizator | Data | 29 martie 2015 10:14:13 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.7 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int n, maxim, ib, jb, start, lb;
int main()
{
fin >> n;
for (int i = 1, x; i <= n; i++)
{
fin >> x;
if (x == 1)
{
start = 1;
ib = jb = 1;
lb = x;
maxim = x;
continue;
}
if (lb + x >= x)
lb += x;
else
{
lb = x;
start = i;
}
if (lb > maxim)
{
maxim = lb;
ib = start;
jb = i;
}
}
fout << maxim << " " << ib << " " << jb;
return 0;
}