Cod sursa(job #2776020)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 18 septembrie 2021 14:26:17
Problema Lowest Common Ancestor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>

using namespace std;

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

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

int main()
{
    usain_bolt();

    int n, l = 1, lmax = 1, rmax = 1;
    long long sum = 0, mx = -2e9;
    fin >> n;
    for(int i = 1; i <= n; ++i) {
        int x;

        fin >> x;
        sum += 1LL * x;
        if(sum > mx) {
            mx = sum;
            lmax = l, rmax = i;
        }
        if(sum < 0) {
            sum = 0;
            l = i + 1;
        }
    }
    fout << mx << " " << lmax << " " << rmax << "\n";
    return 0;
}