Cod sursa(job #1184165)

Utilizator alexandru223Dan Alexandru Dicu alexandru223 Data 11 mai 2014 16:38:03
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
using namespace std;
int a[6000001], n, i, s, nrpoz, h, be, bs, cs, sol;
ifstream fi ( "ssm.in" );
ofstream fo ( "ssm.out" );
int main()
{
    fi >> n; sol = -int(2e9); cs = 1;
    for ( i = 1 ; i <= n ; i++ )
        {
            fi >> a[i];
             if ( s < 0 )
                {
                    s = 0;
                    cs = i+1;
                }
            s = s + a[i];
            if (sol < s)
                {
                    sol = s;
                    bs = cs;
                    be = i;
                }
        }
    fo << sol << ' ' << bs << ' ' << be;
    return 0;
}