Cod sursa(job #2480273)

Utilizator gheorghe_cristiGheorghe Florin Cristi gheorghe_cristi Data 25 octombrie 2019 10:59:11
Problema Subsecventa de suma maxima Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n,x,s, i1,j1, r1,r2,maxx=-1000000000;

int main()
{
    fin>>n;
    for(int i=1;i<=n;++i) {
        fin>>x;
        if(s+x>=x) {
            s+=x;
            j1 = i;
        }else{
            s=x;
            i1=j1=i;
        }
        if(s>maxx) {
            maxx=s;
            r1=i1;
            r2=j1;
        }
    }
    fout<<maxx<<" "<<r1<<" "<<r2;
}