Cod sursa(job #2230121)

Utilizator butasebiButa Gabriel-Sebastian butasebi Data 9 august 2018 10:15:27
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
int n, pozin, pozend, pozinmax, pozendmax, maxx, s, i, x;
int main()
{
    ifstream f("ssm.in");
    ofstream g("ssm.out");
    f >> n;
    pozin = 1;
    for(i = 1;i <= n;i++)
    {
        f >> x;
        if(x > 0)
        {
            s = s + x;
            if(s > maxx)maxx = s, pozinmax = pozin, pozendmax = i;
        }
        else
        {
            s = s + x;
            if(s < 0)s = 0, pozin = i + 1;
        }
    }
    g << maxx << " " << pozinmax << " " << pozendmax;
    return 0;
}