Cod sursa(job #1893812)

Utilizator savigunFeleaga Dragos-George savigun Data 26 februarie 2017 01:16:27
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
using namespace std;

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

int smax = -2000000000, lmax, pmax;

int main() {
    int n, x, s = 0;
    in >> n;

    for (int i = 1; i <= n; ++i) {
        in >> x;
        if (s + x > x) {
            s += x;
            if (s > smax) {
                smax = s;
                pmax = i;
                lmax++;
            }
        } else {
            s = x;
            if (s > smax) {
                smax = s;
                pmax = i;
                lmax = 1;
            }
        }
    }

    out << smax << " " << pmax - lmax << " " << pmax;

    return 0;
}