Cod sursa(job #2308568)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 27 decembrie 2018 13:07:45
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");

void SSM()
{
    int N, i, smax, s, x, st, dr, stmax, drmax;
    fin >> N;
    fin >> s;
    smax = s;
    st = stmax = 1;
    dr = drmax = 1;

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

    fout << smax << " " << ++stmax << " " << ++drmax << "\n";
}

int main ()
{
    SSM();
    return 0;
}