Cod sursa(job #2921074)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 27 august 2022 12:19:40
Problema Subsecventa de suma maxima Scor 95
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>
#include <iostream>

using namespace std;

ifstream f ("ssm.in");
ofstream g ("ssm.out");

int main()
{
    int sc, smax;
    sc = smax = -1;
    int stmax, drmax, stc;
    stc = stmax = drmax = -1;
    
    int n;
    f>>n;
    
    for(int i=1; i<=n; i++){
        int x;
        f>>x;
        if(sc<0){
            sc = x;
            stc = i;
        }else{
            sc+=x;
        }
        if(sc > smax){
            smax = sc;
            drmax = i;
            stmax = stc;
        }
    }
    g<<smax<<' '<<stmax<<' '<<drmax;
    
    

    return 0;
}