Cod sursa(job #2192609)

Utilizator MoldooooooooMoldoveanu Stefan Moldoooooooo Data 6 aprilie 2018 17:52:24
Problema Subsecventa de suma maxima Scor 5
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
#define NMax 6000001
using namespace std;
ifstream fin("ssm.in");
ofstream fout("ssm.out");
int N, i, st, dr, stmax, drmax;
long long int S, Smax;
long long int V[NMax];
int main()
{
	fin >> N;
	for (i = 0; i < N; i++) {
        fin>>V[i];
		if (S + V[i] > 0) {
			S += V[i];
			dr++;
		}
		else {
			i = st + 1;
			st = dr = i;
			S = V[i];
		}
		if (S > Smax) {Smax = S;
		stmax=st;
		drmax=dr;}
	}
	fout << Smax << " " << stmax+1 << " " << drmax+1;
    return 0;
}