Cod sursa(job #2434000)
Utilizator | Barbu Alexandru cyg_Alex_codegician | Data | 30 iunie 2019 12:03:35 |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
int n,x,start,stop,s=0,maxx=0;
fin >> n;
for (int i=1;i<=n;i++)
{
fin >> x;
if (s==0 && s+x>0) start=i;
s+=x;
if (s>maxx)
{
maxx=s;
stop=i;
}
else if (s<0) s=0;
}
fout << maxx << " " << start << " " << stop;
}