Cod sursa(job #612699)

Utilizator psycho21rAbabab psycho21r Data 9 septembrie 2011 17:34:54
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
//Subsecventa de suma maxima - infoarena.ro

#include "fstream"

using namespace std;

int main()
{
	int max_here = 0, max_total = 0, temp, c1, c2, c1_temp = 0;

	ifstream in("ssm.in");
	int n;
	in >> n;
	for (int i = 0; i < n; ++i)
	{
		in >> temp;
		if (max_here < 0)
		{
			max_here = temp;
			c1_temp = i;
		}
		else
			max_here += temp;
		if (max_here > max_total)
		{
			max_total = max_here;
			c1 = c1_temp;
			c2 = i;
		}
	}
	in.close();
	ofstream out("ssn.out");
	out << max_total << " " << c1 << " " << c2 << " " << endl;
	out.close();

	return 0;
}