Cod sursa(job #495730)

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

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

vector best[6000001];

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

	int n, i, k;

	scanf("%d ", &n);

	for(i=1; i<=n; i++){
		scanf("%d ", &k);
		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=-999999, 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;
}