Cod sursa(job #1253590)

Utilizator radu_cebotariRadu Cebotari radu_cebotari Data 1 noiembrie 2014 15:14:55
Problema Subsecventa de suma maxima Scor 95
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include<fstream>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");

int s,bg,ed,x,n,best[6000009];

int main()
{
    int bst = -2000000009;
    in>>n;
    bg = 1;
    in>>x;
    best[1] = x;
    for(int i = 2 ; i <= n ; i++)
    {
        in>>x;
        if(best[i-1] < 0){
            best[i] = x;
            bg = i;
        }
        else{
            best[i] = best[i-1] + x;
            if(bst < best[i]){
                bst = best[i];
                ed = i;
                s = bg;
            }
        }
    }
    out<<bst<<" "<<s<<" "<<ed;
    return 0;
}