Cod sursa(job #2407359)

Utilizator cristianabalcanuCristiana Balcanu cristianabalcanu Data 16 aprilie 2019 19:58:30
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("ssm.in");
ofstream fout ("ssm.out");
int main()
{
    int n;
    fin >> n;
    long long bestmx = -((1LL<<34)-1), bestpi = 0, pi, pt, best = 0;
    for ( int i = 1 ; i <= n; i++ )
    {
        long long x;
        fin >> x;
        if ( best + x > x )
        {
            best = best + x;
        }
        else
        {
            best = x;
            pi = i;
        }
        if ( bestmx < best )
        {
            bestmx = best;
            bestpi= pi;
            pt = i;
        }
    }
    fout << bestmx << " " << bestpi << " " << pt;
    return 0;
}