Cod sursa(job #2824562)

Utilizator antonio_sefu_tauLaslau Antonio antonio_sefu_tau Data 2 ianuarie 2022 17:17:17
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>
#include <iostream>
#define ll long long

using namespace std;

const int dim = 6000005;
int a[dim], n, s, smax = -1 * (1 << 31), start, st, dr;;

int main()
{
    ifstream f("ssm.in");
    ofstream g("ssm.out");
    f >> n;
    for(int i = 1; i <= n; i++)
        f >> a[i];
    for(int i = 1; i <= n; i++)
    {
        if(s < 0)
            s = 0, start = i;
        s += a[i];
        if(s > smax)
            smax = s, st = start, dr = i;
    }
    g << smax << ' ' << st << ' ' << dr;
    return 0;
}