Cod sursa(job #290532)

Utilizator snaked31Stanica Andrei snaked31 Data 28 martie 2009 01:17:19
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <stdio.h>


int n, i, s, sol, p1, p1i, p2;
int x;

int main()

{
	freopen("ssm.in", "r", stdin);
    freopen("ssm.out","w",stdout);
    
	scanf("%d ", &n);
   	s = 0;
    p1 = 1;
    sol = -0x3f3f3f3f;
    
	for (i=1; i<=n; ++i)
    {
    	scanf("%d ", &x);
        if (s < 0)
        {
        	s = x;
            p1 = i;
        }
        else
        	s+=x;
        if (s > sol)
        {
        	sol = s;
            p2 = i;
            p1i = p1;
        }
        else
        if (s == sol && (i-p1) < (p2-p1i))
        {
        	p2 = i;
            p1i = p1;
        }

    }

    printf("%d %d %d\n", sol, p1i, p2);

    return 0;
}