Cod sursa(job #2150202)

Utilizator cristian5379Sasu Cristian cristian5379 Data 3 martie 2018 12:43:53
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include <iostream>
#include <fstream >


using namespace std;

ifstream fin ("file.in");
ofstream fout ("file.out");

int main()
{
    int n,S,smax,stmax,drmax,st,x;
    fin >> n>> x;
    S=smax=x;
    stmax=drmax=st=1;
    for (int i=2;i<=n;i++){

        if (S<0){
            S=0;
            st=i;
        }
        fin >> x;
        S=S+x;
        if (S>smax){

            smax=S;
            stmax=st;
            drmax=i;

        }
    }
    fout << smax <<" "<< stmax << " "<<drmax;
    return 0;
}