Cod sursa(job #1405392)

Utilizator pulseOvidiu Giorgi pulse Data 29 martie 2015 10:23:38
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;

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

int n, maxim, ib, jb, start, sum;

int main()
{
    fin >> n;
    maxim = -int(2e9);
    sum = 0;
    start = 1;
    for (int i = 1, x; i <= n; i++)
    {
        fin >> x;
        if (sum + x < x)
        {
            sum = x;
            start = i;
        }
        else
            sum += x;
        if (sum > maxim)
        {
            maxim = sum;
            ib = start;
            jb = i;
        }
    }
    fout << maxim << " " << ib << " " << jb;
    return 0;
}