Cod sursa(job #495642)

Utilizator cristian9Cristian Zloteanu cristian9 Data 26 octombrie 2010 11:36:58
Problema Subsecventa de suma maxima Scor 0
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].a;
		}
		else{
			best[i].a=k;
			best[i].b=i;
		}
		best[i].c=i;
	}
	
	int max=0, maxi, maxj;
	for(i=1; i<=n; i++)
		if(best[i].a>max){
			max=best[i].a;
			maxi=best[i].a;
			maxj=best[i].b;
		}
	printf("%d %d %d", max, maxi, maxj);
	return 0;
}