Cod sursa(job #3198847)

Utilizator florinul1Iuhas Florin florinul1 Data 30 ianuarie 2024 19:12:36
Problema Subsecventa de suma maxima Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
#include <iostream>

using namespace std;

int n, smax=(1<<31), startmax, stopmax;

int main()
{
    ifstream fin("ssm.in");
    int i, x, sc = 0, stc = 1, stopc = 1;
    fin >> n;
    for (i = 1; i <= n; i++) {
        fin >> x;
        sc += x;
        if (sc <= 0) {
            sc = 0;
            stc = i+1;
            stopc = i+1;
        }
        else {
            if (sc > smax) {
                smax = sc;
                startmax = stc;
                stopmax = stopc;
            }
            stopc++;
        }
    }
    fin.close();
    ofstream fout("ssm.out");
    fout << smax << ' ' << startmax << ' ' << stopmax;
    fout.close();
    return 0;
}