Cod sursa(job #2473937)

Utilizator PodieDohotariu Adrian Podie Data 14 octombrie 2019 15:13:07
Problema Subsecventa de suma maxima Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb

#include <stdio.h>
#include <stdlib.h>
int main() {

    int smax, sc, i, x, n, pc, max, pmax;

    FILE *fin, *fout;
    fin = fopen("ssm.in", "r");
    fout = fopen("ssm.out", "w");
    fscanf(fin, "%d", &n);
    smax = 1 << 31;
    sc = 0;
    for (i = 0; i < n; i++) {
        fscanf(fin, "%d", &x);
        if (x > sc + x) {
            sc = x;

            pc = i;

        } else {


            sc += x;


        }

        if (sc > smax) {


            smax = sc;

            pmax = pc;

            max = i;


        }


    }


    fprintf(fout, "%d %d %d", smax, pmax + 1, max + 1);

    fclose(fin);
    fclose(fout);

    return 0;


}