Cod sursa(job #872573)

Utilizator BeilandArnoldArnold Beiland BeilandArnold Data 6 februarie 2013 11:58:59
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>

int main(){
    std::ifstream fin("ssm.in");
    std::ofstream fout("ssm.out");
    unsigned N; fin>>N;
    int Sir; fin>>Sir;
    unsigned beg=0, end=0, sind=0;
    int bestsum=Sir, best=Sir;
    for(unsigned i=1; i<N; ++i){
        fin>>Sir;
        if(best+Sir>=Sir) best = best+Sir;
        else{ best=Sir; sind=i; }
        if(best>bestsum){
            bestsum=best;
            beg=sind; end=i;
        }
    }
    fout<<bestsum<<' '<<beg+1<<' '<<end+1<<'\n';
}