Cod sursa(job #2211337)

Utilizator ContDeRacistAliniateEBlat ContDeRacist Data 9 iunie 2018 22:23:06
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>

using namespace std;

ifstream cin("ssm.in");
ofstream cout("ssm.out");

int main()
{
    int n, best(-1), maxv = -((1LL<<31) - 1), val, indicei, indicej(0), postj;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> val;
        if (best < 0) {
            postj = i;
            best = 0;
        }
        best += val;
        if (best > maxv) {
            indicei = i;
            indicej = postj;
            maxv = best;
        }
    }
    cout << maxv << " " << indicej +  1<< " " << indicei + 1;
    return 0;
}