Cod sursa(job #2434009)

Utilizator cyg_Alex_codegicianBarbu Alexandru cyg_Alex_codegician Data 30 iunie 2019 12:17:57
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int main()
{
    int n,x,start,start1,stop,s=0,maxx=INT_MIN;
    fin >> n;
    for (int i=1;i<=n;i++)
    {
        fin >> x;
        if (s==0 && s+x>=0) start1=i;
        s+=x;
        if (s>maxx)
        {
            maxx=s;
            if (s<0) start=i;
            else start=start1;
            stop=i;
        }
        if (s<0) s=0;
    }
    fout << maxx << " " << start << " " << stop;
}