Cod sursa(job #2196431)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 19 aprilie 2018 11:35:00
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{
    int n, x, st, dr, stm;
    long s = 0, smax = INT_MIN;

    fin >> n;

    for(int i = 1; i <= n; i++) {
        fin >> x;

        if(x + s > x) {
            s += x;
        } else {
            s = x;
            st = i;
        }

        if(s > smax) {
            smax = s;
            stm = st;
            dr = i;
        }
    }

    fout << smax << " " << stm << " " << dr;

    return 0;
}