Cod sursa(job #1189915)

Utilizator Narcys01Ciovnicu Narcis Narcys01 Data 23 mai 2014 21:49:16
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int main()
{
    int n, i, j, k, k2, s, smax, x;
    fin >> n;
    fin >> x;
    s = smax = x;
    j = k = k2 = 1;
    for (i = 2; i <= n; i++)
    {
        fin >> x;
        if (s < 0)
        {
            k2 = i;
            s = 0;
        }
        if (s > smax)
        {
            smax = s;
            j = i-1;
            k = k2;
        }
        s += x;
    }
    fout << smax << " " << k << " " << j;
    return 0;
}