Cod sursa(job #2257654)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 10 octombrie 2018 11:59:51
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
#include <climits>

#define inf (int)(INT_MAX-1)

std::ifstream InFile("ssm.in");
std::ofstream OutFile("ssm.out");

int indStart = 1, indEnd,
    Max = -inf, Best = -inf;
void DP() {
    int N, x, ind, i = 0; InFile >> N;
    indEnd = N;

    while(N--) {
        i++;
        InFile >> x;

        if(Best < 0)
            Best = x, ind = i;
        else
            Best += x;

        if(Best > Max) {
            indEnd = i;
            indStart = ind;
            Max = Best;
        }
    }   OutFile << Max << ' ' << indStart << ' ' << indEnd << '\n';
}

int main()
{
    DP();

    return 0;
}