Cod sursa(job #2447312)

Utilizator uvIanisUrsu Ianis Vlad uvIanis Data 12 august 2019 20:21:02
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");

int x, n, length{0}, last, first;
long long s{0}, smax{-900000000000};

int main()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
    {
        fin >> x;

        if(s + x < x)
        {
            length = 1;
            s = i;
        }
        else
        {
             s += x;
             length++;

             if(s > smax){
                smax = s;
                last = i;
                first = i - length + 1;
             }
        }
    }

    fout<<smax<<" "<<first<<" "<<last;


}