Cod sursa(job #3339300)

Utilizator AlekuwAlexandru Stefan Pascut Alekuw Data 7 februarie 2026 12:25:26
Problema Subsecventa de suma maxima Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("ssm.in");
ofstream out("ssm.out");


int main()
{
    long long s;
    int n, st = 1, dr = 1, rs, rd;
    long long x, maxi = INT_MIN;
    bool gasit;
    cin >> n;
    cin >> s;
    maxi = s - 1;
    for (int i = 2; i <= n; ++i) {
        cin >> x;
        if (maxi < s) {
            rs = st;
            rd = dr;
            maxi = s;
        }
        if (s + x >= x) {
            s += x;
            dr++;
        }
        else {
            st = dr + 1;
            dr = i;
            s = x;
            gasit = 1;
        }
    }
    if (!gasit) rd ++;
    cout << maxi << " " << rs << " " << rd;
    return 0;
}