Cod sursa(job #1863654)

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

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

int N;
long long s, smax;
long long 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;
}