#include <stdio.h>

struct T
{
	int l ;
	size_t a ;
	size_t b ;
} ;

void funcion(int *tabla, size_t size, struct T *t)
{
	int last, positivos ;
	size_t y, x, z ;

	for(t->l = t->a = t->b = z = y = x = last = positivos = 0; x < size; x++)
	{
		// salteo negativos
		if (!last)
			while(tabla[x] < 0)
			{
				if (tabla[x] > tabla[z])
					z = x ;

				y = ++x ;

				if (x >= size)
				{
					// si no hay ningun numero positivo se toma el mayor negativo
					if (!positivos)
					{
						t->l = tabla[z] ;
						t->a = z ;
						t->b = z+1 ;
					}
					return ;
				}
			}

		positivos = 1 ;
		last += tabla[x] ;

		// si el resultado es mayor a toda la cuenta anterior guardo los datos
		if (last >= t->l)
		{
			t->l = last ;
			t->a = y ;
			t->b = x+1 ;
		}

		// si el resultado es menor o igual que 0 reasigno los contadores
		if (last <= 0)
		{
			y = x+1 ;
			last = 0 ;
		}
	}
}

int main(int argc, char *argv[])
{
	struct T t ;
	int x, tabla[argc] ;

	for (x=1; x < argc; x++)
		tabla[x-1] = atoi(argv[x]) ;

	funcion(tabla, x-1, &t) ;

	for(x=t.a; x < t.b; x++)
		printf("%d ",tabla[x]) ;

	printf("= %d\n",t.l) ;
	return 0 ;
}


