Cod sursa(job #2404444)

Utilizator bruhbruhbruhbruh bruh bruhbruhbruh Data 12 aprilie 2019 19:51:49
Problema Subsecventa de suma maxima Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n;
long long a[6000041];

int main()
{
    fin >> n;
    long long sumax = 0;
    int indi, indj;
    sumax = indi = indj = 0;
    long long sumcurent;
    int ic, jc;
    ic = jc = 0;
    sumcurent = 0;
    for(int i = 0; i < n; i++)
    {
        long long x;
        fin >> x;
        if(sumcurent == 0)
        {
            ic = i;
        }
        sumcurent += x;
        if(sumcurent > 0)
        {
            jc = i;
        }
        if(sumcurent < 0)
        {
            sumcurent = 0;
        }
        if(sumcurent > sumax)
        {
            sumax = sumcurent;
            indi = ic;
            indj = jc;
        }
    }
    fout << sumax << " " << indi+1 << " " << indj+1;
    return 0;
}