Cod sursa(job #672048)

Utilizator feelshiftFeelshift feelshift Data 1 februarie 2012 15:20:37
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
// http://infoarena.ro/problema/ssm
#include <fstream>
using namespace std;

const int oo = 0x3f3f3f3f;

ifstream in("ssm.in");
ofstream out("ssm.out");

int length,bestSum=-oo,sum=-oo,number,Left,Right,tmpLeft,position;

int main() {
	in >> length;

	for(position=1;position<=length;position++) {
		in >> number;

		if(sum < 0) {
			tmpLeft = position;
			sum = number;
		}
		else
			sum += number;

		if(bestSum < sum) {
			bestSum = sum;
			Left = tmpLeft;
			Right = position;
		}
	}

	out << bestSum << " " << Left << " " << Right << "\n";

	in.close();
	out.close();

	return (0);
}