Cod sursa(job #3328754)

Utilizator ionutpop118Pop Ioan Cristian ionutpop118 Data 10 decembrie 2025 09:42:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>

using namespace std;

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

int main()
{
    int n, i, x, s, st, s_max, st_max, dr_max;

    fin >> n >> x;

    s = s_max = x;
    st = st_max = dr_max = 1;

    for (i = 2; i <= n; i++) {
        fin >> x;

        if (s >= 0) {
            s = s + x;
        } else {
            s = x;
            st = i;
        }

        if (s > s_max) {
            s_max = s;
            st_max = st;
            dr_max = i;
        }
    }

    fout << s_max << " " << st_max << " " << dr_max << "\n";
    return 0;
}