Cod sursa(job #3033307)

Utilizator georgecristian2002Raducanu George-Cristian georgecristian2002 Data 23 martie 2023 18:22:32
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

int main(void)
{
    ifstream fin("ssm.in");
    ofstream fout("ssm.out");

    int s, x, n, startul = 1, endul = 1;
    fin >> n;
    s = 0;
    int best_sum = - (1 << 17);

    int helper;

    for (int i = 1; i <= n; ++i) {
        fin >> x;
        if (s < 0) {
            s = x;
            helper = i;
        } else {
            s = s + x;
        }

        if (best_sum < s) {
            best_sum = s;
            startul = helper; 
            endul = i;
        }
    }

    fout << best_sum << " " << startul << " " << endul << "\n";
    fin.close();
    fout.close();
    return 0;
}