Cod sursa(job #495740)

Utilizator cristian9Cristian Zloteanu cristian9 Data 26 octombrie 2010 19:49:56
Problema Subsecventa de suma maxima Scor 85
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include<stdio.h>

struct vector{
	int a, b, c;
};

vector best, nr;

int main(){
	freopen ("ssm.in", "r", stdin);
	freopen ("ssm.out", "w", stdout);

	int n, i, k;

	scanf("%d ", &n);

    best.a=-99999;
    nr.b=1;
	for(i=1; i<=n; i++){
		scanf("%d ", &k);
		if(nr.a+k>=k)
            nr.a+=k;
        else{
            nr.a=k;
            nr.b=i;
        }
        nr.c=i;
        if(nr.a>best.a)
            best=nr;

	}

	printf("%d %d %d ", best.a, best.b, best.c);

	return 0;
}
		/*if(best[i-1].a+k>=k){
			best[i].a=best[i-1].a+k;
			best[i].b=best[i-1].b;
		}
		else{
			best[i].a=k;
			best[i].b=i;
		}
		best[i].c=i;
	}

	int max=-99999, maxi, maxj;
	for(i=1; i<=n; i++)
		if(best[i].a>max){
			max=best[i].a;
			maxi=best[i].b;
			maxj=best[i].c;
		}

    printf("%d %d %d\n", max, maxi, maxj);
	return 0;
}

*/