Cod sursa(job #1875636)

Utilizator WebDesignbyTMGhiorghiu Ioan-Viorel WebDesignbyTM Data 11 februarie 2017 13:28:03
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
#define DM 600000
using namespace std;

ifstream fi ("ssm.in");
ofstream fo ("ssm.out");

int n, s, mx = INT_MIN, a, st, ed, stp, edp;

int main ()
{
    fi >> n;
    fi >> a;
    s = a;
    stp = 1;
    edp = 1;
    for (int i = 2; i <= n; ++i)
    {
        fi >> a;
        if (s + a > a)
        {
            s+=a;
            edp = i;
        }
        if (s > mx)
        {
            st = stp;
            ed = edp;
            mx = s;
        }
        if (s + a < a)
        {
            s = a;
            stp = i;
            edp = i;
        }
    }
    fo << mx << ' ' << st << ' ' << ed;
}