Cod sursa(job #287844)

Utilizator andy_cool977VALEANU ANDREI GABRIEL andy_cool977 Data 25 martie 2009 11:33:23
Problema Subsecventa de suma maxima Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <stdio.h>
#define NM 6000000
#include <limits.h>

int main()
{
int n,v[NM+1],i,st,end,sc=0,smax=INT_MIN;
freopen("ssm.in","r",stdin);
freopen("ssm.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)
	scanf("%d",&v[i]);
st=i=1;
for(i=1;i<=n;i++)
	{
	if(sc<0) {sc=v[i];
						st=i;}
	else sc=sc+v[i];
	if(smax<sc) {smax=sc;
							 end=i;}
	}
printf("%d %d %d",smax,st,end);
return 0;

}