Cod sursa(job #2614736)

Utilizator MocalinnoMoca Andrei Catalin Mocalinno Data 12 mai 2020 16:40:18
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
const string problem("ssm");
ifstream fin(problem + ".in");
ofstream fout(problem + ".out");
pair<int, int> p;
int n, x, st(1), dr;
long long curr, smax(-1e18);
int main() {
    DAU
    fin >> n;
    for (int i = 1; i <= n; ++i) {
        fin >> x;
        curr += x;
        if (curr > smax)
            smax = curr, p = {st, i};
        if (curr < 0)
            curr = 0, st = i + 1;
    }
    fout << smax << ' ' << p.first << ' ' << p.second;
    PLEC
}