Cod sursa(job #2845480)

Utilizator DooMeDCristian Alexutan DooMeD Data 7 februarie 2022 21:49:38
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main () {
    ifstream f ("ssm.in");
    ofstream g ("ssm.out");

    int n; f >> n;
    ll ant = 0;
    ll mx = 0;
    ll now = 0;
    int st, stmx, drmx;
    for(int i=1; i<=n; i++) {
        ll x; f >> x;
        if(x>ant+x) {
            now = x;
            ant = x;
            st = i;
        }
        else {
            now = ant + x;
            ant = now;
        }
        if(now > mx) {
            mx = now;
            stmx = st;
            drmx = i;
        }
    }
    g << mx << " " << stmx << " " << drmx;
    return 0;
}