Cod sursa(job #1875675)

Utilizator WebDesignbyTMGhiorghiu Ioan-Viorel WebDesignbyTM Data 11 februarie 2017 14:00:54
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
#define DM 6000000
using namespace std;

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

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

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