Cod sursa(job #3286455)

Utilizator Manolea_Teodor_StefanManolea Teodor Stefan Manolea_Teodor_Stefan Data 14 martie 2025 11:10:11
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("ssm.in");
ofstream fout("ssm.out");


using ll = long long;
const int nmax = 2 * 1e5 + 1;

struct val {
    int left = 1;
    int right = 1;
    ll val = LLONG_MIN;
} ans,cur;
int n;


int main() {
    fin >> n;
    ll s;
    fin >> s;

    ans.val = s;
    cur = ans;
    for (int i = 2; i <= n; i++) {
        int rd; fin >> rd;
        if (s + rd >= rd) {
            cur.right++;cur.val = s + rd;
            if (cur.val > ans.val) {
                ans = cur;
            } else if (cur.val == ans.val) {
                if (cur.left < ans.left) {
                    ans = cur;
                } else if (cur.left == ans.left and ans.right > cur.right) {
                    ans = cur;
                }
            }
            s += rd;
        } else {
            cur = {i,i,rd};
            s = rd;
        }
    }
    fout << ans.val << ' ' << ans.left << ' ' << ans.right;
    return 0;
}