Cod sursa(job #1044249)

Utilizator GaborGabrielFMI - GabrielG GaborGabriel Data 29 noiembrie 2013 15:24:32
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include<fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");

#define maxn 6000005
unsigned long long N, pmax=1, v[maxn], before[maxn];

int main()
{
	f >> N;

	f >> v[1];
	before[1] = 1;
	for (int i = 2; i <= N; ++i) {
		f >> v[i];
		if (v[i - 1] < 0) {
			before[i] = i;
			pmax = (v[i] > v[pmax]) ? i : pmax;
		}
		else if (v[i] + v[i - 1] > v[pmax])
			pmax = i; 
		if (v[i] + v[i-1] > 0)
			v[i] += v[i - 1], before[i] = before[i - 1];
	}

	g << v[pmax] << ' ' << before[pmax] << ' ' << pmax;

	return 0;
}