Cod sursa(job #2969107)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 22 ianuarie 2023 16:22:15
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
long long n, pozi, pozf, Max, raspi, raspf, S, x;
int main()
{
    f >> n;
    pozi = 1;
    for(int i = 1; i <= n; i ++)
    {
        f >> x;
        S += x;
        if(S < 0)
        {
            pozi = pozf = i + 1;
            S = 0;
        }
        else
        {
            if(Max < S)
            {
                Max = S;
                raspi = pozi;
                raspf = pozf;
            }
            pozf ++;
        }
    }

    g << Max << " " << raspi << " " << raspf;
    return 0;
}