Cod sursa(job #2666778)

Utilizator lenkkaPana Luca lenkka Data 2 noiembrie 2020 15:00:52
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("ssm.in");
    ofstream fout("ssm.out");
    int n;
    fin >> n;
    int sc=0,smax=-2147483648,lc=0,dr;
    for(int i=1;i<=n;i++)
    {
        int x;
        fin >> x;
        lc++;
        if(sc<0)
        {
            sc=0;
            lc=0;
        }
        sc += x;
        if(sc>smax)
        {
            smax=sc;
            dr=i;
        }
    }
    if(dr!=1)
        fout << smax << " " << dr-lc+1 << " " << dr << endl;
    else
        fout << smax << " " << 1 << " " << 1 << endl;
    fout.flush();
    return 0;
}