Cod sursa(job #2892881)

Utilizator LIR16LazarIonutRadu LIR16 Data 23 aprilie 2022 21:03:27
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>

using namespace std;

int n;

int main()
{
    freopen("ssm.in", "r", stdin);
    // freopen("ssm.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int v;
    int dp = 0;
    int dp_max = -1e9, left = -1, right = -1;
    int idx = -1;

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> v;

        if (dp < 0) {
            dp = v;
            idx = i;
        }
        else {
            dp += v;
        }

        if (dp_max < dp) {
            dp_max = dp;
            left = idx;
            right = i;
        }
    }

    cout << dp_max << " " << left + 1 << " " << right + 1;
    return 0;
}