Cod sursa(job #1987209)

Utilizator ArctopusKacso Peter-Gabor Arctopus Data 29 mai 2017 22:39:51
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <vector>
#include <fstream>

#define ll long long

using namespace std;

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

const int NLIM = 6e6;

int N;

int hsum = 0;
int hl, hr;

int sum = -1;
int l, r;

int main()
{
    fin >> N;
    for( hr = 0; hr < N; ++hr )
    {
        int x;
        fin >> x;

        if( x > hsum + x )
        {
            hl = hr;
            hsum = x;
        }
        else
        {
            hsum += x;
        }

        if( hsum > sum )
        {
            sum = hsum;
            l = hl;
            r = hr;
        }
    }

    fout << sum << " " << l + 1 << " " << r + 1;

    return 0;
}