Cod sursa(job #1875658)

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

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

int n, s, mx = -20000000, 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;
        }
    }
    if (s > mx)
    {
        st = stp;
        ed = edp;
        mx = s;
    }
    fo << mx << ' ' << st << ' ' << ed;
}