Cod sursa(job #2193609)

Utilizator Narvik13Razvan Roatis Narvik13 Data 10 aprilie 2018 18:16:21
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("ssm.in");
ofstream o("ssm.out");

int main()
{
    int n, sump, sumax = -2147000000, stmax, drmax, ant = 0, nr;

    sump = 0;

    f >> n;
    for(int i = 1; i <= n; ++i)
    {
        f >> nr;
        sump += nr;

        if(sump > sumax)
        {
            sumax = sump;
            stmax = ant + 1;
            drmax = i;
        }

        if(sump < 0)
        {
            sump = 0;
            ant = i;
        }
    }

    o << sumax << ' ' << stmax << ' ' << drmax << '\n';

    return 0;
}