Cod sursa(job #2666899)

Utilizator stefanmicu.yoda@gmail.comMicro Stefan [email protected] Data 2 noiembrie 2020 16:24:51
Problema Subsecventa de suma maxima Scor 0
Compilator c-32 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <stdio.h>
#include <stdlib.h>

int main()
{
    freopen("ssm.in ", "r", stdin);
    freopen("ssm.out", "w", stdout);
    int n, i, x, sc = -1, st, dr, stmax, drmax;
    int smax = -2147483641;
    scanf("%d", &n);
    for(i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        if(sc < 0)
        {
            sc = 0;
            st = i;
        }
            sc += x;
        if(sc > smax)
        {
            smax = sc;
            stmax = st;
            drmax = i;
        }
    }
    printf("%d %d %d", smax, stmax, drmax);
    return 0;
}