Cod sursa(job #2583492)

Utilizator alexboat10759Alex Mateescu alexboat10759 Data 18 martie 2020 13:18:12
Problema Subsecventa de suma maxima Scor 45
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

int A[100002];

int main()
{
    ifstream fin("ssm.in");
    ofstream fout("ssm.out");

    int n;
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        fin>>A[i];
    }
    int st, dr, Smax = -2000000000, S = -1, start;
    for(int i = 1 ; i <= n ; ++ i)
    {
        if(S < 0)
        {
            S = 0;
            start = i;
        }
        S += A[i];
        if(S > Smax)
        {
            Smax = S;
            st = start;
            dr = i;
        }
    }
    fout << Smax << " ";
    fout << st << " " << dr;
    return 0;
}