Cod sursa(job #1863656)

Utilizator borcanirobertBorcani Robert borcanirobert Data 31 ianuarie 2017 08:28:48
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>
#include <vector>
using namespace std;

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

const int Inf = 0x3f3f3f3f;
int N;
int s, smax{-Inf};
int x;
int sc, dc, st, dr;

int main()
{
    fin >> N;

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

        if ( s + x > x )
            s = s + x, dc++;
        else
            s = x, sc = dc = i;

        if ( smax < s )
        {
            smax = s;
            st = sc;
            dr = dc;
        }
    }

    fout << smax << ' ' << st << ' ' << dr << '\n';

    fin.close();
    fout.close();
    return 0;
}