Cod sursa(job #1474648)

Utilizator AlexandraaaaMereu Alexandra Alexandraaaa Data 22 august 2015 15:28:48
Problema Subsecventa de suma maxima Scor 65
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 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;
		s += x;

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

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

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

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