Cod sursa(job #393807)

Utilizator ghedany92Gheorghita Daniel ghedany92 Data 9 februarie 2010 22:48:11
Problema Secventa 2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream.h>
ifstream fin("secv2.in");
ofstream fout("secv2.out");
long long max,a[6000001],best[6000001];
long n,i,j,pi,pf;
int main()
{
	fin>>n;
	for (i=1;i<=n;i++)
	fin>>a[i];
	/*for (i=2;i<=n;i++)
		{fin>>a[i];
		a[i]+=a[i-1];
		}
	max=a[1];
	for (i=2;i<=n;i++)
		for (j=1;j<i;j++)
			if (a[i]-a[j]>max) {max=a[i]-a[j]; pi=j; pf=i;}*/
	max=a[1];
	for (i=1;i<=n;i++) 
	{
		best[i]=a[i];
		if (best[i]<best[i-1]+a[i]) 
			best[i]=best[i-1]+a[i];
		if (max<best[i])
			{max=best[i]; pf=i;}
	}
	
	fout<<max<<' '; i=pf;
	while (max!=0)
		{max-=a[i]; i--;}
			
	fout<<i+1<<' '<<pf;
	fout.close();
	return 0;
}