Cod sursa(job #3339296)

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

long long s;
int n, st = 1, dr = 1, rs, rd;
long long x, maxi = INT_MIN;
bool gasit;
int main()
{

    in >> n;
    in >> s;

    for (int i = 1; i < n; ++i) {
        in >> x;
        if (maxi < s) {
            rs = st;
            rd = dr;
            maxi = s;
        }
        if (s + x >= x) {
            s += x;
            dr++;
        }
        else {
            st = dr + 1;
            dr = st;
            s = x;
            gasit=  1;
        }
    }
    if (!gasit) rd ++;
    out << maxi << " " << rs << " " << rd;
    return 0;
}