Cod sursa(job #3246126)

Utilizator Nicky_DumitracheNicolae Dumitrache Nicky_Dumitrache Data 1 octombrie 2024 21:58:55
Problema Subsecventa de suma maxima Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>

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