Cod sursa(job #2670053)

Utilizator ICookie9000Tudor Almasan ICookie9000 Data 8 noiembrie 2020 20:04:41
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int x=-2000000005, n, ind1, ind2, s, i, smax, ind1max, ind2max, nrmax;
void versummax()
{
    if(s>smax)
    {
        smax=s;
        ind1max=ind1;
        ind2max=ind2;
    }
}

int main()
{
    fin >> n;
    ind1=1;
    for(i=1;i<=n;i++)
    {
        fin >> x;
        ind2=i;
        if(x>nrmax)
        {
            nrmax=x;
        }
        if(s<0)
        {
            s=x;
            versummax();
            ind1=i;
        }
        else
        {
            s=s+x;
            versummax();
        }
    }
    if(nrmax<0)
        fout << nrmax << " " << ind2max << " " << ind2max;
    else
        fout << smax << " " << ind1max << " " << ind2max;
    return 0;
}