Cod sursa(job #3249095)

Utilizator prares06Papacioc Rares-Ioan prares06 Data 14 octombrie 2024 19:08:42
Problema Subsecventa de suma maxima Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include<bits/stdc++.h>
using namespace std;

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

int n, x, s, smax, pozmax, lmax, poz, l;

int main(){
    fin >> n;

    poz = 1;

    for(int i = 1; i <= n; ++i){
        fin >> x;
        if(s > 0){
            s = s + x;
            ++l;
        }
        else{
            s = x;
            poz = i;
            l = 1;
        }
        if(s > smax){
            smax = s;
            lmax = l;
            pozmax = poz;
        }
    }

    fout << smax << ' ' << pozmax << ' ' << pozmax + lmax - 1;
}