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