Cod sursa(job #3033294)

Utilizator georgecristian2002Raducanu George-Cristian georgecristian2002 Data 23 martie 2023 18:06:07
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

int maxi(int a, int b) {
    if (a > b)
        return a;
    return b;
}

int main(void)
{
    int s, x, n, start, end;
    cin >> n;
    
    s = 0;

    int best_emy = - (1 << 10);

    start = 1;
    end = 1;

    int helper;

    for (int i = 1; i <= n; ++i) {
        cin >> x;
        if (s + x < 0) {
            s = x;
            helper = i;
        } else {
            s = s + x;
        }

        if (best_emy < s) {
            best_emy = s;
            start = helper; 
            end = i;
        }
    }

    cout << best_emy << " " << start << " " << end << "\n";
    return 0;
}