Cod sursa(job #2549114)

Utilizator richardbaczur1Baczur Richard richardbaczur1 Data 17 februarie 2020 12:18:35
Problema Subsecventa de suma maxima Scor 85
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
#define bst_init -2e9

using namespace std;
int n, x, st, dr, i;
int bst = int(bst_init), minind, mini = 0, sum = 0;
int main()
{
    freopen("ssm.in", "r", stdin);
    freopen("ssm.out", "w", stdout);

    scanf("%d", &n);

    for (i = 1; i <= n; ++i)
    {
        scanf("%d", &x);
        sum += x;
        if (bst < sum - mini)
        {
            st = minind + 1;
            dr = i;
            bst = sum - mini;
        }
        if (sum < mini)
        {
            mini = sum;
            minind = i;
        }
    }
    printf("%d %d %d", bst, st, dr);

    fclose(stdin);
    fclose(stdout);
    return 0;
}