Cod sursa(job #517339)

Utilizator Bit_MasterAlexandru-Iancu Caragicu Bit_Master Data 28 decembrie 2010 14:24:18
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
using namespace std;

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

const int INF = 2000000000;

int best = -INF,a;
int best_max = -INF,a_best_max,b_best_max;

int main()
{
	int nr,n;
	f>>n;
	for (int i = 1; i <= n; ++i)
	{
		f>>nr;
		if (best >= 0)                 //best[i] = max(best[i-1] + nr,nr);
			best = best + nr;
		else
		{
			best = nr;
			a = i;
		}
		if (best > best_max)
		{
			best_max = best;
			a_best_max = a;
			b_best_max = i;
		}
	}
	g<<best_max<<" "<<a_best_max<<" "<<b_best_max;
	return 0;
}