Cod sursa(job #1572229)

Utilizator leopop29Pop Leonard leopop29 Data 18 ianuarie 2016 20:11:13
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream f("ssm.in");
    ofstream g("ssm.out");

    int n, p = -1<<30, b = 1, e = 0, m = -1<<30, bm, em;

    for(f>>n;n--;)
    {
        int x;
        f >> x;
        if(p+x >= x)
            ++e;
        else
            b = e+1, e = b;
        p = max(p+x, x);
        if(m < p)
        {
            m = p;
            bm = b;
            em = e;
        }
    }

    g << m << ' ' << bm << ' ' << em;
    return 0;
}