Cod sursa(job #1474650)

Utilizator AlexandraaaaMereu Alexandra Alexandraaaa Data 22 august 2015 15:31:27
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("ssm.in");
ofstream g("ssm.out");
int main(){

	int n, i, j, x, imax, jmax;
	int s, smax;
	f >> n;
	i = imax = jmax = 1;
	f >> s;
	smax = s;

	for (j = 2; j <= n; ++j){
		f >> x;

		if (s < 0) {
			s = x;
			i = j;
		}
		else
			s += x;

		if (s > smax) {
				smax = s;
				imax = i;
				jmax = j;
			}
	}

	g << smax << " " << imax << " " << jmax;

	f.close();
	g.close();
	return 0;
}