Cod sursa(job #2214809)

Utilizator MoldooooooooMoldoveanu Stefan Moldoooooooo Data 20 iunie 2018 10:18:12
Problema Subsecventa de suma maxima Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>
#define NMax 6000001
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int N, i, st, dr, drmax;
long long int Smax, S, lmax, l;
long long int V;
int main()
{
	fin >> N; fin>>S; l=1; drmax=1; Smax=S; lmax=l;
	for (i = 2; i < N; i++) {
            fin>>V;
            if(V+S>V){
                S=V+S;
                l++;
            }
            else {
                S=V;
                l=1;
            }
            if(S>Smax){
                Smax=S;
                drmax=i;
                lmax=l;
            }
	}
	fout << Smax << " " << drmax-lmax+1 << " " << drmax;
    return 0;
}