Cod sursa(job #1018434)

Utilizator dnprxDan Pracsiu dnprx Data 29 octombrie 2013 16:24:41
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("ssm.in");
    int i, n, x, smax, s, stmax, drmax, st;

    fin >> n;
    fin >> s;
    smax = s;
    stmax = drmax = 1;
    st = 1;
    if (s < 0) s = 0;

    for (i = 2; i <= n; i++)
    {
        fin >> x;
        s += x;
        if (s > smax)
        {
            smax = s; stmax = st; drmax = i;
        }
        if (s < 0)
        {
            s = 0; st = i + 1;
        }
    }
    fin.close();

    ofstream fout("ssm.out");
    fout << smax << " " << stmax << " " << drmax << "\n";
    fout.close();

    return 0;
}