Cod sursa(job #1324471)

Utilizator fluture.godlikeGafton Mihnea Alexandru fluture.godlike Data 22 ianuarie 2015 13:17:11
Problema Subsecventa de suma maxima Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <stdio.h>
#define inf -6000023
FILE *fin, *fout;
int n, temp, max = inf, temp1, p1, p2, p3, p4;
int maxn(int a, int b)
{
    return (a>b)?a:b;
}
int main()
{
    fin = fopen("ssm.in", "r");
    fout = fopen("ssm.out", "w");
    fscanf(fin, "%d", &n);
    for(int i = 0; i< n; i++)
    {
            fscanf(fin, "%d", &temp);
            int max1 = inf;
            if(temp + temp1 > max1)
            {
                    max1 = temp + temp1;
                    p4++;
            }
            if(temp > max1)
            {
                    max1 = temp;
                    p3 = i+1;
                    p4 = i+1;
            }
            temp1 = maxn(temp + temp1, temp);
            if(max1 > max)
            {
                    max = max1;
                    p1 = p3;
                    p2 = p4;
            }
    }
    fprintf(fout, "%d %d %d\n", max, p1, p2);
    fclose(fin);
    fclose(fout);
    return 0;
}