Cod sursa(job #2958802)

Utilizator ingrid2328Nagy Ingrid ingrid2328 Data 28 decembrie 2022 13:13:31
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>

const long long ValMax=(long long)9999999999;
using namespace std;

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

int n, indin, indsf, i, nr, indincrt, indsfcrt;
long long sumcrt=-ValMax, summx=-ValMax;
int main()
{
    fin>>n;
    for (i=1;i<=n;i++){
        fin>>nr;
        if (sumcrt+nr<nr){
            sumcrt=nr;
            indincrt=indsfcrt=i;
        }
        else{
            sumcrt+=nr;
            indsfcrt++;
        }
        if (sumcrt>summx){
            summx=sumcrt;
            indin=indincrt;
            indsf=indsfcrt;
        }
    }
    if (sumcrt>summx){
        summx=sumcrt;
        indin=indincrt;
        indsf=indsfcrt;
    }
    fout<<summx<<' '<<indin<<' '<<indsf;
    return 0;
}