Cod sursa(job #3246153)

Utilizator Nicky_DumitracheNicolae Dumitrache Nicky_Dumitrache Data 2 octombrie 2024 07:30:52
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

int main()
{
    int x;
    int ii, n, i, s, max = -999999999, i1 = 0, i2 = 0;
    std::ifstream fi("ssm.in");
    std::ofstream fo("ssm.out");
    fi >> n;
    for (i = s = 0; i < n; i++)
    {
        fi >> x;
        s += x;
        if (s > max) max = s, i2 = i + 1, ii=i1;
        if (s < 0)
            s = 0, i<=n-2? i1 = i + 2:i1=n;
    }
    fo << max << ' ' << ii << ' ' << i2;
}